Example
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sumeven=0,sumodd=0,n;
clrscr();
printf("Enter the number n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if(i%2==0)
{
else
{
sumodd=sumodd+i;
}
}
printf("sum of even number is:%d",sumeven);
printf("\nsum of odd number is:%d",sumodd);
getch();
}
/*=======================================================================
OUTPUT
Enter the number n:4
sum of even number is:6 // 2 + 4
sum of odd numbe is:4 // 1 + 3
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sumeven=0,sumodd=0,n;
clrscr();
printf("Enter the number n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if(i%2==0)
{
sumeven
=
sumeven + i
else
{
sumodd=sumodd+i;
}
}
printf("sum of even number is:%d",sumeven);
printf("\nsum of odd number is:%d",sumodd);
getch();
}
/*=======================================================================
OUTPUT
Enter the number n:4
sum of even number is:6 // 2 + 4
sum of odd numbe is:4 // 1 + 3
*/
No comments:
Post a Comment