Home >>c programs >c program to find sum of even and odd numbers

c program to find sum of even and odd numbers

Write Program to Print Sum of even and odd from 1 to 100

This c program calculate the print the sum of even and odd numbers 1 and the maximum limit value. It allows the user to enter the number from 1 to 100.

Let's take an example :

#include<stdio.h>    
int main()
{    
int even=0;
int odd=0;
for(int i=1;i<=100;i++)
{
	if(i%2==0)
	{
	even=even+i;
	}
	else
	{
	odd=odd+i;
	}    
}
printf("Sum of even is %d\n",even);
printf("Sum of odd is %d",odd);
return 0;  
}    
Output :
Sum of even is 2550
Sum of odd is 2500