Sum of even and odd numbers Program in C

Sum of even and odd numbers Program in C
Sum of even and odd numbers Program in C

WAP to print sum of even and odd numbers from 1 to N numbers.

#include<stdio.h>
void main()
{
	int i,n,sumEven=0,sumOdd=0;
	printf("Enter number=");	
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		if(i%2==0)
		{
			sumEven=sumEven+i;
		}
		else
		{
			sumOdd=sumOdd+i;
		}
	}
	printf("\nSum of even numbers=%d",sumEven);	
	printf("\nSum of odd numbers=%d",sumOdd);	
}

Output:

Enter number=10

Sum of even numbers=30
Sum of odd numbers=25
b. tech. bca c language tutorial learn c language mca study c language
Recent Posts