Page 2 of 3

Re: 10783 - Odd Sum

Posted: Thu Jun 25, 2009 4:34 pm
by wayne_911
Thx a lot, mf. Finally i can fully utilize this webpage to enhance my programming skill.

Re: 10783 - Odd Sum

Posted: Thu Jun 25, 2009 4:35 pm
by wayne_911
Thx a lot, mf. Finally, i can fully utilize this webpage to enhance my programming skill.

Re: 10783 - Odd Sum

Posted: Sat Jul 04, 2009 8:03 pm
by mhn
getting wa...why??can anyone plz help me..


#include<stdio.h>

int main(){
int a,b,i,j,k,sum,c;

while(scanf("%d",&k)==1){
c=0;
for(i=0;i<k;i++){
scanf("%d %d",&a,&b);
sum=0; c++;
for(j=a;j<=b;j++){

if(j%2==1) sum=sum+j;
else continue;

}
printf("case %d:%d\n",c,sum);
}


}
return 0;
}

Re: 10783 - Odd Sum

Posted: Sat Jul 04, 2009 10:01 pm
by mf
Your output format is wrong.

And use [code]...[/code] tags to post any source code! And no "plz", please!

Re: 10783 - Odd Sum

Posted: Fri Aug 20, 2010 10:30 am
by refat_ruet
i am new at progarmming..... i am having problem with this problem.. it keep saying runtime error.. here is the source code:
#include<stdio.h>
int main(){
int n,i,j,l,s,m=0,*a,*b;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d %d",&a,&b);}
for(i=0;i<n;i++){
s=0;
for(j=a;j<=b;j++){
if(j%2==1)
s+=j;}m++;
printf("case %d: %d\n",m,s);}
return 0;
}

Re: 10783 - Odd Sum

Posted: Fri Aug 27, 2010 8:18 am
by sohel
You didn't allocate any memory for the pointers a and b.
Try avoiding pointers if it's not required.

Re: 10783 - Odd Sum

Posted: Wed Oct 06, 2010 8:43 pm
by Rakib Hasan6
#include<stdio.h>
int main(){
int a,b,i,s,n,j=1;
scanf("%d",&n);

while(j<=n){
s=0;
scanf("%d %d",&a,&b);
if((a%2)==0){


i=a+1;}
else
i=a;
while(i<=b){
s=s+i;
i=i+2;
}
printf("case %d: %d\n",j,s);
j++;

}

return 0;
}

Re: 10783 - Odd Sum

Posted: Wed May 04, 2011 10:31 pm
by HIRA_iit_du
Can anybody help me what's the wrong with this code?
#include<stdio.h>

int main(){
int n,i,j,l,s,m=0,a[100],b[100];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d %d",&a,&b);}
for(i=0;i<n;i++){
s=0;
for(j=a;j<=b;j++){
if(j%2==1)
s+=j;}m++;
printf("case %d: %d\n",m,s);}

return 0;
}

Re: 10783 - Odd Sum

Posted: Wed May 04, 2011 11:21 pm
by sohel
Case should have an uppercase C. :)

Re: 10783 - Odd Sum

Posted: Thu Mar 29, 2012 7:12 am
by Khaldu
plzzzz tell me why i getting runtime error...
#include<stdio.h>
int main()
{ int i,j,sum,a,b,n;
scanf("%d",&n);

for(i=1;i<=n;i++)
{
scanf("%d",&a);
scanf("%d",&b);
sum=0;
for(j=a;j<=b;j++)
{

if(j%2!=0)
sum=sum+j;
}
printf("Case %d: %d\n",i,sum);


}

}

Re: 10783 - Odd Sum

Posted: Fri Mar 30, 2012 3:30 am
by brianfry713
Try adding "return 0;" at the end of your code.

10783- Odd sum

Posted: Fri May 17, 2013 11:07 pm
by sno
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;
}

10783- Why WA??

Posted: Fri May 17, 2013 11:19 pm
by sno
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;
}

Re: 10783- Why WA??

Posted: Tue May 21, 2013 2:42 am
by brianfry713
For the sample input, the correct output is:

Code: Select all

Case 1: 9
Case 2: 8
Your output:

Code: Select all

Case 1 :9
Case 2 :8

Re: 10783- Odd sum

Posted: Tue May 21, 2013 2:50 am
by brianfry713
Don't double post.