# Why do i get wrong answer for the SUMTRIAN problem and Sorry about my code

#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
// insert code here…
int maxNumberOfTestCases =0,maxnumberOfLines=0,numberOfColumns=0,k=0,numberOfRows=0;
int a[100][100];

scanf("%d",&maxNumberOfTestCases);

for (k=0; k<maxNumberOfTestCases; k++)
{
scanf("%d\n",&maxnumberOfLines);

for (numberOfRows = 0; numberOfRows < maxnumberOfLines; numberOfRows++)
{
for (numberOfColumns = 0; numberOfColumns <= numberOfRows; numberOfColumns++)
{
scanf("%d",&a[numberOfRows][numberOfColumns]);
}
}
}

while (numberOfRows-->0)
{
for (numberOfColumns = 0; numberOfColumns < numberOfRows; numberOfColumns++)
{
a[numberOfRows-1][numberOfColumns] =  a[numberOfRows-1][numberOfColumns] +
a[numberOfRows][numberOfColumns]   >
a[numberOfRows-1][numberOfColumns] +
a[numberOfRows][numberOfColumns+1] ?
a[numberOfRows-1][numberOfColumns] +
a[numberOfRows][numberOfColumns]   :
a[numberOfRows-1][numberOfColumns] +
a[numberOfRows][numberOfColumns+1];

}
}

printf("%d",a[0][0]);
return 0;
}

I finally figured how to do this,there were two mistakes in my code:

1. outer while loop goes inside the testcases loop.

2. printf("%d\n",a[0][0]

#include <stdio.h>
#include <stdlib.h>

#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
// insert code here…
int maxNumberOfTestCases =0,maxnumberOfLines=0,numberOfColumns=0,k=0,numberOfRows=0;
int a[100][100];

scanf("%d",&maxNumberOfTestCases);

for (k=0; k<maxNumberOfTestCases; k++)
{
scanf("%d\n",&maxnumberOfLines);

for (numberOfRows = 0; numberOfRows < maxnumberOfLines; numberOfRows++)
{
for (numberOfColumns = 0; numberOfColumns <= numberOfRows; numberOfColumns++)
{
scanf("%d",&a[numberOfRows][numberOfColumns]);
}
}
while (numberOfRows-->0)
{
for (numberOfColumns = 0; numberOfColumns < numberOfRows; numberOfColumns++)
{
a[numberOfRows-1][numberOfColumns] =  a[numberOfRows-1][numberOfColumns] +
a[numberOfRows][numberOfColumns]   >
a[numberOfRows-1][numberOfColumns] +
a[numberOfRows][numberOfColumns+1] ?
a[numberOfRows-1][numberOfColumns] +
a[numberOfRows][numberOfColumns]   :
a[numberOfRows-1][numberOfColumns] +
a[numberOfRows][numberOfColumns+1];

}
}
printf("%d\n",a[0][0]);
}

return 0;

}