Ad Code

Responsive Advertisement

Uri - Beecrowd | 1071 | Sum of Consecutive Odd Numbers I

beecrowd | 1071

Sum of Consecutive Odd Numbers I

By Neilor Tonin, URI Brazil


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 Input Sample Output

6
-5

5

15
12

13

12
12

0

N.B.: It's better if you solve this by your own. Thank you!

  URI - BEECROWD Online Judge 1071 Solve in C:                                          

//Solved by Intesar
#include <stdio.h>

int main() {

    int x,y,sum=0;

    scanf("%d%d",&x,&y);
    y=y+1;
    while(y<x)
    {
        if(y%2!=0)
        {
            sum=sum+y;
        }
        y++;
    }
    printf("%d\n",sum);

    return 0;
}

Post a Comment

0 Comments

Ad Code

Responsive Advertisement