Uva Solution – 10783 Odd Sum

Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int testcase,cs,j,a,b,low,high;

    int counter=0;
    scanf("%d",&testcase);

    for(cs=1; cs<=testcase; cs++)
    {
        int sum=0;
        scanf("%d %d",&a,&b);
        if(a>b)
        {
            low=b;
            high=a;
        }else{
            low=a;
            high=b;
        }
        for(j=low; j<=high; j++)
        {

            if(j%2!=0)
            {
                sum=sum+j;
            }

        }
        printf("Case %d: %d\n",cs,sum);
    }
    return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *