C program to print the sum of even and odd numbers from 1 to n.
Program :
#include<stdio.h>
#include<conio.h>
void main()
{ int i,n,even_sum=0,odd_sum=0;
clrscr();
printf("Enter the maximum limit value\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
even_sum=even_sum+i;
else
odd_sum=odd_sum+i;
}
printf("The sum of even numbers upto %d =%d\n",n,even_sum);
printf("The sum of odd numbers upto %d =%d",n,odd_sum);
getch();
}
Comments
Post a Comment