10783 - Odd Sum
Moderator: Board moderators
Re: 10783 - Odd Sum
Thx a lot, mf. Finally i can fully utilize this webpage to enhance my programming skill.
Re: 10783 - Odd Sum
Thx a lot, mf. Finally, i can fully utilize this webpage to enhance my programming skill.
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;
}
#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
Your output format is wrong.
And use [code]...[/code] tags to post any source code! And no "plz", please!
And use [code]...[/code] tags to post any source code! And no "plz", please!
-
- 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;
}
#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
You didn't allocate any memory for the pointers a and b.
Try avoiding pointers if it's not required.
Try avoiding pointers if it's not required.
-
- 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;
}
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;
}
-
- 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;
}
#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
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);
}
}
#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);
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10783 - Odd Sum
Try adding "return 0;" at the end of your code.
Check input and AC output for thousands of problems on uDebug!
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;
}

#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??
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;
}
#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;
}
-
- 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:Your output:
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!
-
- 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!