Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
sol1.c File Reference

Problem 15 solution More...

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for sol1.c:

Functions

unsigned long long number_of_paths (int N)
 At every node, there are 2 possible ways to move -> down or right. More...
 
int main (int argc, char **argv)
 Main function.
 

Detailed Description

Problem 15 solution

Author
Krishna Vedala

Function Documentation

◆ number_of_paths()

unsigned long long number_of_paths ( int  N)

At every node, there are 2 possible ways to move -> down or right.

Since it is a square grid, there are in all, 2N steps with N down and N right options, without preference for order. Hence, the path can be be traced in N out of 2N number of ways. This is the same as binomial coeeficient.

18 {
19  unsigned long long path = 1;
20  for (int i = 0; i < N; i++)
21  {
22  path *= (N << 1) - i;
23  path /= i + 1;
24  }
25 
26  return path;
27 }
N
#define N
number of digits of the large number
Definition: sol1.c:109