#include<stdio.h>
#include<conio.h>
void main()
{
int i, num, odd=0,
even=0;
clrscr();
printf(“Enter the number:”);
scanf(“%d”,&num);
for(i=1;i<=num,i++)
if(i%2==0)
{
even = even+i;
}
ilse
{
odd = odd + i;
}
}
printf(“\n Sum of all odd numbers: %d”,odd);
getch();
}
Output:
Enter the
number: 5
No comments:
Post a Comment