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

Write a C# program using repl.it that asks the user for three integers and prints the...
Write a C# program using repl.it that asks the user for three integers and prints the average value as a double. Example calculation (3 + 6 + 7) / 3 = 5.33333333333333 Given the data above, the output should be similar to: The average for the values entered is: 5.33333333333333 As always comments in your code are expected (what why how etc… ) Submit your repl.it link to the assignment dropbox text submission area.
Write a C# program using Repl.it that asks the user for a numeric grade between 0...
Write a C# program using Repl.it that asks the user for a numeric grade between 0 and 100, and displays a letter grade using the following conversion table: Numeric grade   Letter grade 90 < grade <= 100 A 80 < grade <= 90 B 70 < grade <= 80 C 60< grade <= 70 D grade <= 0.0 F Don’t forget the comments in your code. The output should be similar to: Enter the test score: 87 The letter grade...
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...
This is C++, please insert screenshot of output please. Part1: Palindrome detector Write a program that...
This is C++, please insert screenshot of output please. Part1: Palindrome detector Write a program that will test if some string is a palindrome Ask the user to enter a string Pass the string to a Boolean function that uses recursion to determine if something is a palindrome or not. The function should return true if the string is a palindrome and false if the string is not a palindrome. Main displays the result ( if the string is a...
c program Write a program that asks the user to enter a sequence of 15 integers,...
c program Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
write these programs in c++ using getch() function Write a program that reads 20 integers from...
write these programs in c++ using getch() function Write a program that reads 20 integers from a user using a while loop and determines and prints whether each of those integers is an even number. Write a program that uses a while statement to read integers from a user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters -1.
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++ 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: ----------------------...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT