C programming code to add even and odd numbers up to n

Share This Topic:

Course Details

Field of Study: Computer Science and Engineering
Course Name: C Programming
Course Description: C programming code to add even and odd numbers up to n

Code
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,sO=0,sE=0;
printf(“Enter the number\n”);
scanf(“%d”,&n);
for(int i=1;i<=n;i++)
{
if(i%2==0)
sE=sE+i;
else
sO=sO+i;
}
printf(“The sum of even Nos up to %d=%d\nThe sun of odd Nos up to %d=%d”,n,sE,n,sO);
getch();
}

Share this article:
Previous Post: C programming code to list all factors of n

December 2, 2014 - In Academics, Computers

Next Post: C programming code to find minimum value of an array

December 2, 2014 - In Academics, Computers

Related Posts

Leave a Reply

Your email address will not be published.