Welcome

>>>Welcome to my "CODE BAZAR"
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others

Update ✔✔✔ Upcoming programming book (.pdf) "Programming Contest (data structures and algorithms) by Md. Mahbub Hasan & "Graph Algorithms" by Safayat Asraf "****** Date: 20 March, 2019****Hazrat Ali****

Monday, 14 November 2016

URI-1071

URI Online Judge | 1071

Sum of Consecutive Odd Numbers I

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
Read two integer values and Y. Print the sum of all odd values between them.

Input

The input file contain two integer values.

Output

The program must print an integer number. This number is the sum off all odd values between both input values that must fit in an integer number.
Sample InputSample Output
6
-5
5
15
12
13
12
12
0

Solution...

#include<stdio.h>
int main()
{
    int a,i,b,sum=0;
    scanf("%d%d",&a,&b);
    if(a%2==0){
        for(i=a-1;i>b;i=i-2){
            sum=sum+i;
        }

    }
    if(a%2!=0){
        for(i=a-2;i>b;i=i-2){
            sum=sum+i;
        }
    }
    printf("%d\n",sum);
    return 0;
}

No comments:

Post a Comment