Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Saturday, September 3, 2022

C Program to Find Sum and average of Array Elements

C Program to Find Sum and average of Array Elements


#include <stdio.h>

#include<conio.h>

main()

{

int i, sum=0,n;

float avg=0;

printf("Enter how many numbers\n");

scanf("%d",&n);

int a[n];

printf("Enter %d number\n",n);

for (i=0;i<n;i++)

{

scanf("%d",&a[i]);

sum=sum+a[i];

}

avg=sum/n;

printf("\n sum of an array=%d",sum);

printf("\n Average of an array=%f",avg);

getch();

}

OUTPUT:


Note: In above program number are input in an array according to the user requirement and display their sum and average.

You may also read:



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages