URI / BEE CROWD 1071 - Sum of Consecutive Odd Numbers I Solution in C,C++,Python | URI Online Judge Solution 1071 - Sum of Consecutive Odd Numbers I
Read two integer values X 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 |
15 | 13 |
12 | 0 |
URI / BEE CROWD 1071 - Sum of Consecutive Odd Numbers I Solution in C,C++,Python | URI Online Judge Solution 1071 - Sum of Consecutive Odd Numbers I
Demonstration:
URI Problem 1071 Solution in C :
#include <stdio.h>
int main()
{
int x, y, sum = 0, i;
int min, max;
scanf("%d%d", &x,&y);
if(x < y){
min = x;
max = y;
}else{
max = x;
min = y;
}
for(i = (min + 1); i < max; ++i)
{
if(i % 2 != 0){
sum += i;
}
}
printf("%d\n", sum);
return 0;
}
good job!
ReplyDeleteThanks,Stay with us❤️
ReplyDeleteHi brother, Will you continue solving URI problems ? U haven't posted in this section for a long time.
ReplyDeleteI will continue solving URI / BEE problems from next months. Thanks for supporting me.
ReplyDelete#include
ReplyDeleteint main(){
int a,b,i;
int sum=0;
scanf("%d %d",&a,&b);
if(a>b){
for(i=(b+1); i<a; i++){
if(i%2!=0){
sum=sum+i;
}
}
}else{
for(i=(a+1); i<b; i++){
if(i%2!=0){
sum=sum+i;
}
}
}
printf("%d\n",sum);
return 0;
}