-
-
Save bojieli/05b2574e45a87d2e9adb to your computer and use it in GitHub Desktop.
Project Euler #18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define N 15 | |
int main() { | |
int i, j, max = 0; | |
int a[N][N]; | |
for (i=0; i<N; i++) | |
for (j=0; j<=i; j++) | |
scanf("%d", &a[i][j]); | |
for (i=1; i<N; i++) { | |
a[i][0] += a[i-1][0]; | |
a[i][i] += a[i-1][i-1]; | |
for (j=1; j<i; j++) | |
a[i][j] += (a[i-1][j] > a[i-1][j-1] ? a[i-1][j] : a[i-1][j-1]); | |
} | |
for (j=0; j<N; j++) | |
if (a[N-1][j] > max) | |
max = a[N-1][j]; | |
printf("%d\n", max); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment