Advertisement
5_2007-2008 Math #194650

sum of even,odd numbers

This code is useful to compute the sum of odd , even numbers and both upto certain limit.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
#include<stdio.h>
#include<conio.h>
void main()
{
int n,se=0,so=0,ch,i;
clrscr();
printf("enter the number limit:");
scanf("%d",&n);
printf("\n1.odd\n2.even\n3.both\n");
printf("enter your choice of displaying the result:");
scanf("%d",&ch);
for(i=0;i<=n;i++)
{
if(i%2==0)
se=se+i;
}
for(i=0;i<=n;i++)
{
if(i%2!=0)
so=so+i;
}
switch(ch)
{
case 1:
printf("\nsum of even numbers=%d",se);
break;
case 2:
printf("\nsum of odd numbers=%d",so);
break;
case 3:
printf("\nsum of even numbers=%d",se);
printf("\nsum of odd numbers=%d",so);
printf("\nsum of both numbers=%d",(so+se));
break;
default:
printf("\nenter a valid choice\n");
}
getch();
}
Original Comments (3)
Recovered from Wayback Machine