Monday, August 16, 2010

SUM AND AVERAGE OF EVEN NUMBERS WITHIN THE LIMIT

0 comments
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,lower,upper,sum=0,count=0,temp;
float average;
clrscr();
printf("Enter the lower limit: ");
scanf("%d",&lower);
printf("Enter the upper limit: ");
scanf("%d",&upper); 
if(lower>upper)
{
temp=lower;
lower=upper;
upper=temp;
}
for(i=lower+1;i<upper;i++)
{
if(i%2==0)
{
sum=sum+i;
count++;
}
}
average=sum/count;
printf(" Sum of even numbers between %d and %d is=%d ",lower,upper,sum);
printf(" Average is=%f",average);
getch();
}

Leave a Reply