Write a program to prompt the user to enter five numbers. The program then stores numbers in an array, compute and output the sum and average.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
/*
Write a program to prompt the user to enter five numbers.
The program then stores numbers in an array, compute and output the sum and average.
*/
#define MAX_SIZE 5
int main()
{
float Num[MAX_SIZE],Sum=0,Avg=0;
int n;
for(n=0;n<MAX_SIZE;n++)
{
printf("\n\tEnter No. %d: ",n+1); scanf("%f",&Num[n]);
Sum = Sum + Num[n];
}
Avg = Sum/MAX_SIZE;
printf("\n\tInput Numbers: ");
for(n=0;n<MAX_SIZE;n++) printf("%.1f, ",Num[n]);
printf("\n\tSum = %.2f",Sum);
printf("\n\tAverage = %.2f",Avg);
return(0);
}
Comments
Leave a comment