Friday 4 September 2015

WAP to find out the sum and average of all the numbers within the given range?

#include<stdio.h>
#include<conio.h>
void main()
{int a,b,c;
float sum=0,avg;
printf("enter a number");
scanf("%d",&a);
printf("enter other number");
scanf("%d",&b);
for(c=a;c<=b;c++)
sum=sum+c;

avg=sum/(b-a+1);
printf("\nsum%f",sum);
printf("\navg%f",avg);
getch();
}




No comments:

Post a Comment