Search found 2 matches

by sno
Fri May 17, 2013 11:19 pm
Forum: Volume 107 (10700-10799)
Topic: 10783 - Odd Sum
Replies: 34
Views: 14854

10783- Why WA??

Why I am getting WA in this code?

#include<stdio.h>
int main()
{
int a,b,t,n,i,j,k=1,sum;
scanf("%d",&t);
for(i=0;i<t;i++)
{
for(n=0;n<1;n++)
{
scanf("%d\n" "%d",&a,&b);
sum=0;
for(j=a;j<=b;j+=2)
{
sum=sum+j;
}
}
printf("Case %d :%d\n",k,sum);
k++;
}
return 0;
}
by sno
Fri May 17, 2013 11:07 pm
Forum: Volume 107 (10700-10799)
Topic: 10783 - Odd Sum
Replies: 34
Views: 14854

10783- Odd sum

What's wrong with this code? :roll:
#include<stdio.h>
int main()
{
int a,b,t,n,i,j,k=1,sum;
scanf("%d",&t);
for(i=0;i<t;i++)
{
for(n=0;n<1;n++)
{
scanf("%d\n" "%d",&a,&b);
sum=0;
for(j=a;j<=b;j+=2)
{
sum=sum+j;
}
}
printf("Case %d :%d\n",k,sum);
k++;
}
return 0;
}

Go to advanced search