Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

not able to locate error although program is running successfully on ideone--sums in triangle

$
0
0

include<stdio.h>

void sums(int arr[101][101],int n) { int i,j; for(i=n;i>0;i--) //going on the last element of last second line { //adding bigger element to it from the next two elements below it for(j=n;j>0;j--) //in the same way goin to a[0][0] { arr[i-1][j-1] += (arr[i][j-1]>arr[i][j] ? arr[i][j-1] : arr[i][j]); } } printf("%d\n",arr[i][j]); //we reached to a[0][0] which gives maximum sum }

int main() { int arr[101][101],n,t,i,j; //declaring an array to store numbers scanf("%d",&t); //taking number of testcases while(t--) { scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<=i;j++) scanf("%d",&arr[i][j]); } sums(arr,n); } return 0; }


Viewing all articles
Browse latest Browse all 40121

Trending Articles