C program to calculate sum and average of element stored in 1D array.

#include<stdio.h>
#include<conio.h>
#define N 5
void main(){
int list[N],i,sum;
float avg;
clrscr();
printf("Enter Elements of List Array\n");
for(i=0;i<N;i++){
printf("Enter %d Element = ",i+1);
scanf("%d",&list[i]);
sum=sum+list[i];
}
avg=(float)sum/i;
printf("Sum = %d and Average = %f\n",sum,avg);
getch();
}

No comments:

Post a Comment