Easy math july lunchtime 2019

i did not understand which test case is wrong help please!!!.
#include <stdio.h>

int main(void)
{ int a[100],n,t,i,sum,b,c=0,j;
scanf("%d",&t);
while(t–)
{ scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{ for(j=i+1;j<n;j++)
{ b=a[i]*a[j];
sum=0;
while(b)
{ sum=sum+b%10;
b=b/10;
}
if(c<sum)
c=sum;
}
}
printf("%d\n",c);
}
return 0;
}

First tip!
Reformat the code or provide the solution link like this:
https://www.codechef.com/viewsolution/25447248
Anyway,
I can’t exactly see where you did wrong our algos are almost matching.
But i feel like you must have made a small mistake

hello @prabhat63,
I see what you have done wrong here, you have initialized c=0 before your loop for test cases. It is a good practice to initialize all variables inside the loop for test cases. What’s happening here is that for example, in 1st test case your “c” becomes 90. So it will remain 90 for other test cases as well and when comparing if(c<sum), it will give wrong results. Just put c=0 inside while(t–) and it should work.

1 Like

you shoukd have initialized c=0 inside the testcase loop…according to your code c will be the max value of your previous test case for a new test case