Question

write C program using function to read 20 float numbers and print the average of them...

write C program using function to read 20 float numbers and print the average of them after changing the negative to positive number.

Homework Answers

Answer #1

Code:

#include <stdio.h>
void print_average() //defining print_average()
{
int i=1;
float num=0.0f,sum=0.0f;
for(i=1;i<=20;i++) //Looping 20 times
{
//Inputting number
printf("Enter Number %d: ",i);
scanf("%f",&num);
//summing the numbers after making negative ones positive
sum=sum+((num<0)?-num:num);
}
//Printing average
printf("The average of numbers: %f",(sum/20.0));
}
int main()
{
print_average(); //calling print_average() function
return 0;
}

Sample Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python program that asks users to input 10 float numbers (using a while statement),...
Write a Python program that asks users to input 10 float numbers (using a while statement), and print the minimum number.
Write a full C++ program to read a series of integer numbers from standard input and...
Write a full C++ program to read a series of integer numbers from standard input and print them out in reverse order, one per line. You may assume that there will be a minimum of 2 numbers to read and a maximum of 200.
float sum( float x, float y, float z ) ​program in c++
Here are the function prototypes for your homeworkWrite out the actual functions themselves Also, create a main function that demonstrates that all four functions work The user should be able to provide four values to your program (three floats and an int) Your program should then use your four new functions and also display the results to the user NONE of these functions should print values themselvesfloat sum( float x, float y, float z ); // returns the sum of three floatsfloat mean( float...
C++ INSTRUCTIONS Problem Specification : Write a program that reads a group of numbers from the...
C++ INSTRUCTIONS Problem Specification : Write a program that reads a group of numbers from the user and places them in an array of type float. Once the numbers are stored in the array, the program should average and print the result. Use pointer notation wherever possible. Program Output (with Input Shown in Bold): Enter number: 2 Enter another (y/n)? y Enter number: 4 Enter another (y/n)? y Enter number: 6 Enter another (y/n)? y Enter number: 8 Enter another...
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers...
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 55000 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules:...
1- Write a program to print only the even numbers from 100 to 200 2- Write...
1- Write a program to print only the even numbers from 100 to 200 2- Write a program to print the odd numbers from 22 – 99 3- Write a program to calculate howe many even number from 10 to 120 1- Write a program to find only the even numbers for 12 different numbers 2- Write a program to find the odd numbers for 10 different numbers 3- Write a program to calculate howe many even number and how...
instructions read in 4 numbers. sum up the 4 numbers. print the four numbers and the...
instructions read in 4 numbers. sum up the 4 numbers. print the four numbers and the sum Using the Marie editor and compiler, write a program that will satisfy these requirements. Cut and paste your code (from the editor) into the answer area of this question C+
Write a C program that when you type in five numbers, it will print the number...
Write a C program that when you type in five numbers, it will print the number from the smallest one to the largest one.(if you type in 2, 1, 3, 5, 4, the output will be 1, 2, 3, 4, 5 ) You may need more than one function to complete this mission.
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
C programming language. Write a program to print reverse of all the numbers from m to...
C programming language. Write a program to print reverse of all the numbers from m to n using functions with arguments and no return type. The inputs in the program will be m and n variables and need to take these variables as arguments.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT