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

#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;
}

you need to set all array elements to zero after handling any one test case.Here is the link to accepted code CodeChef: Practical coding for everyone

1 Like

thanks a lot @rishabh1994