C Program to Find Sum and Average of N Numbers

Program


#include<stdio.h>
#include<conio.h>

int main()
{
	 int n, i;
	 float num, sum = 0, avg;
	 clrscr();
	 printf("How many numbers?\n");
	 scanf("%d",&n);
	 i=1;
	 while(i<=n)
	 {
	  printf("Enter number-%d: ",i);
	  scanf("%f", &num);
	  sum = sum + num;
	  i++;
	 }
	 avg = sum/n;
	 printf("\nSum = %0.2f", sum);
	 printf("\nAverage = %0.2f", avg);
	 getch();
	 return(0);
}

Output of above program :

How many numbers?
4 ↲
Enter number-1: 67 ↲
Enter number-2: 89 ↲
Enter number-3: 99 ↲
Enter number-4: 56 ↲
Sum = 311.00
Average = 77.75

Note: ↲ indicates ENTER is pressed.