Wednesday 28 March 2012


TO DISPLAY EVEN AND ODD NUMBERS WITHIN A RANGE SEPERATELY ALSO DISPLAY THEIR SUM AND AVERAGE




#include<stdio.h>
Void main()
{
Int lower,upper,even,odd,count,temp;
Float evensum=0.0,oddsum=0.0,evenavg,oddavg;
Clrscr();
Printf(“enter the lower bound:”);
Scanf(“%d”,&lower);
Printf(“enter the upper bound:”);
Scanf(“%d”,&upper);
If(lower>upper)
{
Temp=lower;
Lower=upper;
Upper=temp;
}
If(lower%2==0)
Even=lower+2;
Else
Even=lower+1;
Printf(“even numbers between %d and %d are :\n”,lower,upper);
For(count=0;even<upper;even+=2,++count)
{
Printf(“%d\t”,even);
Evensum+=even;
}
Evenavg=avensum/count;
Printf(“sum of the even numbers from %d to %d is %g”,lower,upper,evensum);
Printf(“average of the even numbers from %d to %d is %g\n\n”,lower,upper,evenavg);
if(lower%2=1)
odd=lower+2;
else
odd=lower+1;
printf(“odd numbers from %d to %d are\n”,lower,upper);
for(count=0;odd<upper;odd+=2,++count)
{
Printf(“%d\t”,odd);
Oddsum+=odd;
}
Oddavg=oddsum/count;
Printf(“\nsum of the odd numbers from %d to %d is %g”,lower,upper,oddsum);
Printf(“\naverage of the odd numbers from %d to %d is %g”,lower,upper,oddavg);
Getch();
}

No comments:

Post a Comment