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();
}

Add a Comment

Your email address will not be published. Required fields are marked *