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<stdio.h>
#include<conio.h>
void main()
{
int i, sum=0;
clrscr();
for(i=1; i<=100; i = i+2)
{
sum = sum + i;
}
printf("Sum of all odd numbers between 1 - 100 is: %d", sum);
getch();
}
Sum of all odd numbers between 1 - 100 is: 2500