Friday 9 January 2015

C Program to find the Average of all the elements in an array

This is a C Program which finds  the average of all the elements in an array.

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i;
    float sum=0,average;
    printf("How many numbers ?\t");
    scanf("%d",&n);
    float numbers[n];
    for(i=0;i<n;i++)
    {
        printf("Enter number %d\t",i+1);
        scanf("%f",&numbers[i]);
    }
    for(i=0;i<n;i++)
        sum=sum+numbers[i];

    average=sum/n;
    printf("\nThe average of %d  numbers you entered is  :%f \t ",n,average);
    return 0;
}

OUTPUT :
C - Average of all the elements in an array


No comments:

Post a Comment