Please write a simple C program for the following requiremen

Please write a simple C program for the following requirement:

-Prompt the user to input few integer values (insert these values into an array). Then write a function which takes array as parameter and calculates the sum and average of those numbers in the array.

Thank you for the help!

Solution

#include <stdio.h>
#include <stdlib.h>
int getSum(int a[])
{
int sum=0,i;
for(i=0; i<10; i++)
sum+=a[i];
return sum;
}
int main()
{
int a[10],i,sum=0;
double average;

printf(\"Enter 10 integer values:\");
for(i=0; i<10; i++)
scanf(\"%d\",&a[i]);
sum=getSum(a);
average=sum/10.0d;
printf(\"Sum of array elements is :%d\ \",sum);
printf(\"Average of 10 array elements is :%f\ \",average);
return 0;
}

OUTPUT:

Enter 10 integer values:1 2 3 4 5 6 7 8 9 10

Sum of array elements is :55
Average of 10 array elements is :5.500000

Please write a simple C program for the following requirement: -Prompt the user to input few integer values (insert these values into an array). Then write a fu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site