## 10783 - Odd Sum

Moderator: Board moderators

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

### Re: 10783 - Odd Sum

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

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

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

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

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

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

### Re: 10783 - Odd Sum

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

#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

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

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

### Re: 10783 - Odd Sum

Case should have an uppercase C.

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

### Re: 10783 - Odd Sum

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

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

What's wrong with 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;
}

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

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

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

### Re: 10783- Why WA??

For the sample input, the correct output is:

Code: Select all

``````Case 1: 9
Case 2: 8``````

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

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