In this program user ask to find out the average of n Numbers. User declares some variables that are used to contain the value and some elements to be assumed for computation as it is. Like variable N has to be assumed for finding average. While asking about the number quantity user also use While condition to the content. While (count < n) in condition prints the value of x and increment operator for increasing the number. In the end the method to be used for the calculating the average of N number. In the end to display the result in the end.
Problem Statement:
This is c Program that asks the user to find the average of N numbers.
- Declaring the Variables.
- Using while condition.
- Using average calculating method.
- Display result on the screen.
Here is C source code for calculating the average of N numbers. The output of this program shown below.
void main( )
{
int n, count = 1;
float x, average, sum = 0;
printf("How many Numbers? " ) ;
scanf ("%d",&n) ;
while (count < n)
{
printf ("x = " ) ;
scanf("%f", &x);
sum += x;
++count;
}
average = sum/n;
printf("\nThe Average is %f\n", average);
}