C Program to show sum of N elements of array & show the average

/*  Write a C Program to show sum of  N elements of array & show the average.   */
===========================================================
#include<stdio.h>
#include<conio.h>
void main()
{
int a[n],i,sum=0;
float av;
clrscr();
printf(“enter elements of an aaray: ”);
for(i=0;i<n;i++)
scanf(“%d”,&a[n]);
for(i=0;i<n;i++)
sum=sum+a[n];
printf(“sum=%d”,sum);
av=sum/10;
printf(“average=%.2f”,av);
getch();
}

Output:
======
enter elements of an array: 4
5
6
1
2
3
5
5
4
7
sum=42
average=4.22

No comments: