Question

In: Computer Science

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 second function readValue to read in an integer value. Put the prompt and scanf statements in the function and remove from main. Call the function three times from main since only one value can be returned at one time pass by value.The function header will look something like this:int readValue(void)STOP! Get this part working before going to part 3.

3. Call a third function to calculate the product of the three integers.Print the product from main.The function header will look something like this:int product (int n1, int n2, int n3)STOP! Get this part working before going to part 4.

4. After the first three functions are working, remove the print statements for average and product from main and create a fourth function called printResults. This function will receive the average and the product and will print them. It will not return a value. The function header will look something like this:void printResults(int prod, float ave)

Solutions

Expert Solution

C PROGRAM

#include <stdio.h>
//called function
float average(int n1,int n2,int n3)
{
float avg = 0;
//calculates the average
avg = n1+n2+n3/3;
// returns the average
return avg ;
}
// called function
int read(void)
{
int num=0;
printf("\nEnter a integer:");
//reads the input
scanf("%d",&num);
return num;
}
// called function
int product(int n1,int n2,int n3)
{
//calculates the product
int pro = n1*n2*n3;
//returns the product
return pro;
}
//called function ,
void printResults(int prod,float ave)
{
//prints the average, product
printf("Average of 3 Integeres:%f\n",ave);
printf("Product of 3 Integeres:%d",prod);
}
//main fucntion
int main()
{
//variables declaration
int n1,n2,n3;
int re1,re2,re3,pro;
float avg = 0;
printf("Enter a 3 intgeres between 1 and 100:\n");
//reads the input from user
scanf("%d",&n1);
scanf("%d",&n2);
scanf("%d",&n3);
//calling a function & passing the parameters & returned value is stored in avg variable
avg = average(n1,n2,n3);
// calling a function 3 times and returned value is stored in varaibles
re1 = read();
re2 = read();
re3 = read();
//calling a function, passing the parameter , returned value is stored in pro variable
pro = product(re1,re2,re3);
//calling a function , passing the parameter
printResults(pro,avg);
  

return 0;
}

OUTPUT


Related Solutions

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 program that prompts user to enter integers one at a time and then calculates...
Write a program that prompts user to enter integers one at a time and then calculates and displays the average of numbers entered. Use a while loop and tell user that they can enter a non-zero number to continue or zero to terminate the loop. (Switch statement) Write a program that prompts user to enter two numbers x and y, and then prompts a short menu with following 4 arithmetic operations: Chose 1 for addition Chose 2 for subtraction Chose...
Problem description Write a C++ program that prompts the user to enter two non-negative integers, firstNum...
Problem description Write a C++ program that prompts the user to enter two non-negative integers, firstNum and secondNum. The program then prints all palindromic primes (Links to an external site.) between firstNum and secondNum, inclusive. A palindromic number is a number whose digits are the same forward or backward (e.g., 12321). A palindromic prime is a prime number that is also a palindromic number (e.g., 101). You must implement and use the following functions as prototyped below: /// --------------------------------------------------------------- ///...
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
Write a program that prompts the user to enter a 3 x 3 matrix of double...
Write a program that prompts the user to enter a 3 x 3 matrix of double values and tests whether it is a positive Markov matrix. There will be two methods which will be called from the main method: public static double [] [] createArray() 1. Creates a 3 by 3 two dimensional array of doubles 2. Prompts the user for values as shown in the sample run 3. Stores the numbers in the array in the order entered 4....
*JAVA PROGRAM* Write a do loop that prompts a user to enter an integer between 1...
*JAVA PROGRAM* Write a do loop that prompts a user to enter an integer between 1 and 100 inclusive. The user will be repeatedly prompted until they input a valid integer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT