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:...
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
( USE C++ ) The program prompts the user to enter a word. The program then...
( USE C++ ) The program prompts the user to enter a word. The program then prints out the word with letters in backward order. For example, if the user enter "hello" then the program would print "olleh" show that it works .
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
C programming. Write a program that prompts the user to enter a 6x6 array with 0...
C programming. Write a program that prompts the user to enter a 6x6 array with 0 and 1, displays the matrix, and checks if every row and every column have the even number of 1’s.
Write a C++ console program that prompts a user to enter information for the college courses...
Write a C++ console program that prompts a user to enter information for the college courses you have completed, planned, or are in progress, and outputs it to a nicely-formatted table. Name the CPP as you wish (only use characters, underscores and number in your file name. DO NOT use blank). Its output should look something like this: Course Year Units Grade ---------- ---- ----- ----- comsc-110 2015 4 A comsc-165 2016 4 ? comsc-200 2016 4 ? comsc-155h 2014...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT