In: Computer Science
please using Repl.it basic C-programing
part1
Write a program that requests 5 integers from the user and
stores them in an array. You
may do this with either a for loop OR by getting a string from
stdin and using sscanf to store formatted input in each spot in the
array.
part2
Add a function to the program, called get_mean that determines the mean, which is the average of the values. The function should be passed the array and the size of the array, but use const so that it cannot be changed, only accessed. It should return a double, which is the calculated mean. The main function will print the value.
//Function prototype: double get_mean(const int [], int);
//Program:
#include<stdio.h>
double get_mean(const int [],
int);
//function prototype
int main()
{
int a[5];
printf("Enter 5
integers:\n");
//requesting for input
for(int i=0; i<5;
i++)
//loop for getting the input
{
scanf("%d",&a[i]);
//getting the input using array in loop
}
double
m=get_mean(a,5);
//function call for mean of the integers
printf("\nThe mean of the numbers
is:%.2f\n",m); //printing
the mean
return 0;
}
double get_mean(const int a[],int
n)
//function definition
{
double sum=0.0;
for(int i=0; i<n; i++)
{
sum+=a[i];
//calculating the sum
}
double mean =
sum/n;
//calculatig the mean
return
mean;
//returning the mean
}
//Output: