Program not terminating... maybe due to problem in loop....

link text enter code here
``#include<stdio.h>
#include<stdlib.h>
int main()
{
int t,n,i,a[10000];
long long int c,sum;
scanf("%d",&t);
while(t–)
{
sum=0;
scanf("%d %lld",&n,&c);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);

	}
	for(i=0;i<n;i++)
	{
		
		sum=sum+a[i];
		
	}
	if(sum<=c)
	printf("Yes");
	else
	printf("No");
	
}
return 0;

}

I don`t think there is any problem with the code , except that new line is not printed , but that do not cause the program not to terminate .
It will be good if u also give the link of the question or the solution .

plz click on link text above and you will get the question…

In the code submitted you have used the wrong condition in the for loop .

for(i=0;i<=10000;i++) should be changed to for(i=0;i< n;i++)
and for(i=0;a[i]!=’\0’;i++) should be changed to for (i=0;i< n;i++)
Also add new line .

Here is your corrected code.


[1]


  [1]: http://www.codechef.com/viewsolution/4121746
1 Like

i submitted ur sol. with little modification and it got accepted
here it is:->
/*

#include<stdio.h>

#include<stdlib.h>
int main() { int t,n,i,a[10000];
long long int c,sum; scanf("%d",&t);
while(t–) { sum=0; scanf("%d %lld",&n,&c);
for(i=0;i<n;i++) {
scanf("%d",&a[i]);
sum+=a[i];
}
/* for(i=0;i<n;i++)
{

    sum=sum+a[i];
}*/
if(sum<=c)
printf("Yes\n");
else
printf("No\n");

}
return 0;
}

*/

yes… it will work this way also…