Question

1- Write a program to read 10 numbers and find the average of these numbers. Use...

1- Write a program to read 10 numbers and find the average of these numbers. Use a while loop to read these numbers and keep track of input numbers read. Terminate the while loop with a sentinel value.

2- Now modify the program to find the maximum of these numbers as well. The program should print the number of elements read as input and run until -1 is entered. (-1 is the sentinel that terminates the loop and the program) To find the maximum, you want to read the first number outside the loop and assign it to the max variable.
As you read each number you must use the if statement and check it against max.

In C language please.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:

#include <stdio.h>


int main()
{
int sum=0,i,num;

// looping to take 10 values
printf("Enter 10 values");
for(i=0;i<10;i++){
scanf("%d",&num);

// adding to sum
sum+=num;
}

// printing average
printf("Average : %f ",sum/10.0);
  
return 0;
}

Answer 2:

#include <stdio.h>


int main()
{
int i,max,num;
printf("Enter values -1 to exit");
scanf("%d",&max);
// reading values
for(i=0;;i++){
scanf("%d",&num);
// if user enters -1, break the loop
if(num==-1)
break;
// checking with current max
if(num>max)
max=num;

}
printf("Number of values entered : %d \n",i+1);
printf("Max number : %d ",max);
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
1- Write a program to read 10 numbers and find the average of these numbers. Use...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that calculates the average of a stream of non-negative numbers. The user can...

    Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...

  • It needs to be done in JAVA Please don't use the flag=true method. I need it...

    It needs to be done in JAVA Please don't use the flag=true method. I need it done in another way. The user should input the number of numbers they are going to enter. Your job is to find the maximum and the minimum of these numbers. The output of the program if the user does not enter a negative number and all iterations successfully terminate, will be the maximum number, the minimum number and their difference(max-min). If the user inputs...

  • (java) Write a While loop that prompts the user for only even numbers. Keep prompting the...

    (java) Write a While loop that prompts the user for only even numbers. Keep prompting the user to enter even numbers until the user enters an odd number. After the loop ends, print the sum of the numbers. Do not include that last odd number. You should not store the numbers in an array, just keep track of the sum. Make sure to use a break statement in your code. You may assume that a java.util.Scanner object named input has...

  • Objectives: Use the while loop in a program Use the do-while loop in a second program...

    Objectives: Use the while loop in a program Use the do-while loop in a second program Use the for loop in a third program Instructions: Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format: Fahrenheit Celsius 25 ? . . . . . . . . Turn in the source and the output from Part A. Part B. Code a while...

  • •Write a java program to read 10 numbers and print them in reverse order. Modify your...

    •Write a java program to read 10 numbers and print them in reverse order. Modify your program to work for N numbers given by the user Extend your program to find the average of these numbers Extend your program to find the smallest number of these numbers Extend your program to find the largest number of these numbers •Write a program to read 10 numbers and print them in reverse order. Modify your program to work for N numbers given...

  • In C++ 2. Write a program that allows the user to enter a series of positive...

    In C++ 2. Write a program that allows the user to enter a series of positive numbers between 1 and 100 and displays the smallest and largest of the numbers entered. The program should not store the numbers that were entered, only keep track of the smallest and largest ones. The program should continue accepting numbers until the value 0 is entered and then display the results. If a number out of range is entered, tell the user it is...

  • Write a C++ program to read an unknown number of integer values and find the sum...

    Write a C++ program to read an unknown number of integer values and find the sum of only negative integers. Use variable n to store the user input. Hint: Check Example6E.cpp (Lecture 6) Note: Use the "Check" button to verify your answer. You can modify your code and check until you get it right. For example: Test Input Result -11 A list of integers -10 12 1 14 -1

  • Write a program that allows the user to enter a series of exam scores. The number...

    Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop...

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • /* I'm trying to write this program here but my problem is getting the program to...

    /* I'm trying to write this program here but my problem is getting the program to save the user input to "int data" but cannot because it is part of the struct. What do I have to do in order to get this to work? (Language is C++) Write a program that prompts the user to enter numbers on the screen and keep adding those numbers to a linked list. The program stops when user enters -999. Hint: Use a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT