/* Program to find
the sum of even and odd numbers from 1 to 100 */
#include<stdio.h>
#include<conio.h>
void
main()
{
int count,even_sum=0,odd_sum=0;
clrscr();
count=1;
while(count<=100)
{
if(count%2==0)
even_sum=even_sum+count;
else
odd_sum=odd_sum+count;
count++;
}
printf("Range:1-100\n");
printf("\nSum of even
numbers=%d",even_sum);
printf("\nSum of odd
numbers=%d",odd_sum);
getch();
}
OUTPUT
Range:1-100
Sum
of even numbers=2550
Sum
of odd numbers=2500
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.