Refer following program to print the sum of odd number and even number separately:
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,i,even=0,odd=0;
clrscr();
printf("Enter a number ");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
if(i%2==0)
even=even+i;
else
odd=odd+i;
}
printf("n sum of the event=%d",even);
printf("n sum of the oddt=%d",odd);
getch();
} Hope this helps you out with your problem.
**)
I have tried the given code but it didn’t solve my problem. Please try to provide some other solution.
Bookmarks