In this program, we will display the sum of all odd numbers from 1 to 100. We have used for loop and will increment a number by 2 and make sum of it in previous result. Finally we will print sum of console.
#include<iostream>
using namespace std;
int main()
{
int i, sum=0;
for(i=1; i<=100; i = i+2)
{
sum = sum + i;
}
cout<<"Sum of all odd numbers between 1 - 100 is: " << sum;
return 0;
}
Sum of all odd numbers between 1 - 100 is: 2500