1071 - Sum of Consecutive Odd Numbers I - URI Online Judge || URI Online Judge 1071 Sum of Consecutive Odd Numbers I Solution
Problem Name:
Sum of Consecutive Odd Numbers I
Problem Code: 1071
Judge: URI Online Judge
Problem link:
1071 - Sum of Consecutive Odd Numbers I
Solution on GitHub:
1071 - Sum of Consecutive Odd Numbers I
URI Online Judge 1071 - Sum of Consecutive Odd Numbers I Solution in C++/Cpp
#include <iostream>
using namespace std;
int main()
{
int x, y, max, min, sum = 0;
cin >> x >> y;
if (x == y)
{
cout << 0 << endl;
}
else
{
if (x > y)
{
max = x;
min = y;
}
else
{
min = x;
max = y;
}
for (int i = min + 1; i < max; i++)
{
if (i % 2 != 0)
{
sum = sum + i;
}
}
cout << sum << endl;
}
return 0;
}
