10783 - Odd Sum

All about problems in Volume 107. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

wayne_911
New poster
Posts: 4
Joined: Thu Jun 25, 2009 10:02 am

Re: 10783 - Odd Sum

Post by wayne_911 » Thu Jun 25, 2009 4:34 pm

Thx a lot, mf. Finally i can fully utilize this webpage to enhance my programming skill.

wayne_911
New poster
Posts: 4
Joined: Thu Jun 25, 2009 10:02 am

Re: 10783 - Odd Sum

Post by wayne_911 » Thu Jun 25, 2009 4:35 pm

Thx a lot, mf. Finally, i can fully utilize this webpage to enhance my programming skill.

mhn
New poster
Posts: 4
Joined: Mon Jun 22, 2009 7:05 am

Re: 10783 - Odd Sum

Post by mhn » Sat Jul 04, 2009 8:03 pm

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;
}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 10783 - Odd Sum

Post by mf » Sat Jul 04, 2009 10:01 pm

Your output format is wrong.

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

refat_ruet
New poster
Posts: 3
Joined: Fri Aug 20, 2010 10:24 am

Re: 10783 - Odd Sum

Post by refat_ruet » Fri Aug 20, 2010 10:30 am

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;
}

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10783 - Odd Sum

Post by sohel » Fri Aug 27, 2010 8:18 am

You didn't allocate any memory for the pointers a and b.
Try avoiding pointers if it's not required.

Rakib Hasan6
New poster
Posts: 1
Joined: Wed Oct 06, 2010 7:18 pm

Re: 10783 - Odd Sum

Post by Rakib Hasan6 » Wed Oct 06, 2010 8:43 pm

#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;
}

HIRA_iit_du
New poster
Posts: 1
Joined: Wed May 04, 2011 10:20 pm

Re: 10783 - Odd Sum

Post by HIRA_iit_du » Wed May 04, 2011 10:31 pm

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;
}

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10783 - Odd Sum

Post by sohel » Wed May 04, 2011 11:21 pm

Case should have an uppercase C. :)

Khaldu
New poster
Posts: 2
Joined: Wed Mar 21, 2012 3:54 pm

Re: 10783 - Odd Sum

Post by Khaldu » Thu Mar 29, 2012 7:12 am

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);


}

}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10783 - Odd Sum

Post by brianfry713 » Fri Mar 30, 2012 3:30 am

Try adding "return 0;" at the end of your code.
Check input and AC output for thousands of problems on uDebug!

sno
New poster
Posts: 2
Joined: Fri May 17, 2013 10:39 pm

10783- Odd sum

Post by sno » Fri May 17, 2013 11:07 pm

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;
}

sno
New poster
Posts: 2
Joined: Fri May 17, 2013 10:39 pm

10783- Why WA??

Post by sno » Fri May 17, 2013 11:19 pm

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10783- Why WA??

Post by brianfry713 » Tue May 21, 2013 2:42 am

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
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10783- Odd sum

Post by brianfry713 » Tue May 21, 2013 2:50 am

Don't double post.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 107 (10700-10799)”