Tuesday, 8 May 2012

UVa 10783 Odd Sum Solution

#include<stdio.h>
int main()
{
int a,b,c,sum,i,j;
while(scanf("%d",&c)==1)
{for(j=1;j<=c;j++)
    {scanf("%d%d",&a,&b);
    sum=0;
    if(a%2==0)
    a=a+1;
    if(b%2==0)
    b=b-1;
    for(i=a;i<=b;i=i+2)
    sum=sum+i;
    printf("Case %d: %d\n",j,sum);}
}
return 0;
}

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. #include

    int main()
    {
    int a,b,j=1,t,i=0,sum;
    scanf("%d",&t);

    start:
    if ((t>=1) &&(t<=100))
    {
    scanf("%d%d",&a,&b);
    if((a>=0)&& (a<=b)&&(b<=100))
    {
    sum=0;
    for (i=a;i<=b;i++)
    if (i%2!=0)
    sum=sum+i;
    printf("Case %d: %d\n",j,sum);
    }
    else
    return 0;
    }

    j++ ;
    if (j<=t)
    {
    goto start;
    }


    return 0;
    }

    ReplyDelete
  5. #include
    int main()
    {
    int a,b,n,i,sum=0,l;
    while(scanf("%d",&n)!=EOF)
    {
    for(l=1;l<=n;l++)
    {
    scanf("%d",&a);
    scanf("%d",&b);
    {
    for(i=a;i<=b;i=i+1)
    {
    if(i%2!=0) {sum=sum+i;}
    }
    }
    printf("Case %d: %d\n",l,sum);
    sum=0;
    }
    }
    return 0;
    }

    ReplyDelete
  6. #include
    int main()
    {
    int a,b,c,sum,i,j;
    while(scanf("%d",&c)==1)
    {for(j=1;j<=c;j++)
    {scanf("%d%d",&a,&b);
    sum=0;
    if(a%2==0)
    a=a+1;
    if(b%2==0)
    b=b-1;
    for(i=a;i<=b;i=i+2)
    sum=sum+i;
    printf("Case %d: %d\n",j,sum);}
    }

    return 0;
    }

    ReplyDelete