Program
#include <stdio.h> int main() { printf("************************************************************"); printf("\n************************************************************"); printf("\n** WAP to find average of elements of an array **"); printf("\n** Created by Sheetal Garg **"); printf("\n** Assistant Professor **"); printf("\n** Phone No:9467863365 **"); printf("\n************************************************************"); printf("\n************************************************************\n"); int n,i,a[5]; float sum=0,avg; printf("Enter no. of elements in the arrayn"); scanf("%d",&n); printf("enter array elements"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0; i<n; i++) sum=sum + a[i]; avg=sum/n; printf("Average of elements of array is %f",avg); return 0; }
Output
*************************************************************************** *************************************************************************** ** WAP to find average of elements of an array ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** *************************************************************************** *************************************************************************** Enter no. of elements in the array 4 enter array elements 4 2 1 5 Average of elements of array is 3.000000