Question

In: Computer Science

please using Repl.it basic C-programing part1 Write a program that requests 5 integers from the user...

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);

Solutions

Expert Solution

//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:


Related Solutions

C++ programing Write a main function that  reads a list of integers from a user, adds to...
C++ programing Write a main function that  reads a list of integers from a user, adds to an array using dynamic memory allocation, and then displays the array. The program also displays the the largest element in the integer array. Requirement: Using pointer notation.
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
C++ Write a program that prompts the user to enter 50 integers and stores them in...
C++ Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs separated by a ';'. An example of the program is shown below: list[0] = 15 is the sum of: ----------------------...
Write a C++ code using while loop which is getting the two integers from the user,...
Write a C++ code using while loop which is getting the two integers from the user, and output how many numbers are multiples of 5, and how many numbers are multiples of 7 between the two integers (inclusive).
C Program 1. Write a program that prompts the user to enter 3 integers between 1...
C Program 1. Write a program that prompts the user to enter 3 integers between 1 and 100 from the keyboard in function main and then calls a function to find the average of the three numbers. The function should return the average as a floating point number. Print the average from main.The function header line will look something like this:float average(int n1, int n2, int n3) STOP! Get this part working before going to part 2. 2. Create a...
C++ code please: Write a program that first gets a list of integers from input. The...
C++ code please: Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates how much to multiply the array by. Finally, print out the entire array with each element multiplied by the last input. Assume that the list will always contain less than 20 integers. Ex: If the input is 4 4 8 -4 12...
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
Write MIPs program that will read two integers from the user and compute for the sum...
Write MIPs program that will read two integers from the user and compute for the sum and difference of the two integers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Write a program that uses a while statement to read integers from the user and prints...
Write a program that uses a while statement to read integers from the user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters 999. The average should be output with 4 digits of precision. c++ please ASAP
Using C++ Write a program that reads a text from the keyboard until the user presses...
Using C++ Write a program that reads a text from the keyboard until the user presses the “Enter” key. Your program must count the number of uppercase alphabets (A through Z), lowercase alphabets (a through z), digits (0 through 9) and any other characters. The other character count value should NOT include the “Enter” key. Display the count on the screen. You must use the in-built C++ character I/O functions in this program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT