Solution to Problem 15 on ProjectEuler.net


Improve your writing skills in 5 minutes a day with the Daily Writing Tips email newsletter.

The problem:

——-
Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.

p_015

How many routes are there through a 2020 grid?
——-

My Solution

#include <stdio.h>

int main(){
  int i,j,x,y;
  long long int mat[21][21]; 

  i=0;
  for (j=0;j<21;j++) 
    mat[i][j]=1; 

  j=0;
  for (i=0;i<21;i++)
    mat[i][j]=1; 

  for (i=1;i<21;i++)
    for (j=1;j<21;j++)
      mat[i][j]=mat[i-1][j]+mat[i][j-1]; 

  for (i=0;i<21;i++){
    for (j=0;j<21;j++)
      printf("%lld ",mat[i][j]); 
    printf("n");
    }

  return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *