Question
Answer using programming in C only.

6 pts Use a while loop to complete the following: Prompt the user to enter integers one by one, until the user enters a negat
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main() {
    int sum = 0, count = 0, num;
    while (1) {
        printf("Enter an integer(negative to exit): ");
        scanf("%d", &num);
        if (num < 0) {
            break;
        }
        sum += num;
        ++count;
    }
    printf("Sum = %d\n", sum);
    printf("Average = %lf\n", sum/(double)count);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Answer using programming in C only. 6 pts Use a while loop to complete the following:...
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
  • 17. (2 points) C++ Using a while loop, write the code statements to sum 10 integers...

    17. (2 points) C++ Using a while loop, write the code statements to sum 10 integers entered by a user. Display the sum. Hint: Be sure to declare, initialize, and use appropriate variables to count the repetitions and accumulate the sum.

  • This is for C++ programming: Write a while loop that finds the average of all of...

    This is for C++ programming: Write a while loop that finds the average of all of the whole numbers entered from the user, until a -1 is entered (the -1 should not be included in the calculation of the average.

  • C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based...

    C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based off of 9). Program Info:   #9. Write a program that reads in ten whole numbers and that outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once...

  • using while loop

    Sum of Numbers: Write a program that asks the user for a positive integer value.The program should use a loop to get the sum of all the integers from 1 up to the number entered.For Example, if the user enters 50, the loop will find the sum of 1,2,3,4,…50.C++

  • (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...

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • 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...

  • Answer each of the following questions about loops in C++. In each question, LABEL the three...

    Answer each of the following questions about loops in C++. In each question, LABEL the three parts of the loop. a.) Write a while statement that will ask the user for integers until the user enters the sentinel value of -1. Declare all needed variables. b.) Write a for statement that will print out all the multiples of 3 between 1 and 200. Declare any needed variables. c.) Write a do while loop that will ask the user for characters...

  • write a programming code for the following problem using Visual Basic Studio VB. Write a program that will allow the user to enter series of mumbers and will give some useful statistics about the mam...

    write a programming code for the following problem using Visual Basic Studio VB. Write a program that will allow the user to enter series of mumbers and will give some useful statistics about the mambers Enter Numbers Button Click-Allow the user to enter series of nambers using imput dialog boxes. Use a loop and add the numbers to the listBox as they are input.. Prompt the user to enter"x" to stop addang numbers. Compute Statistics Button Click-Compute the following statistics...

  • What is a "sentinel value"? What is the format for a while loop? What is the...

    What is a "sentinel value"? What is the format for a while loop? What is the format for a do-while loop? .Write some instructions which will read a series of numbers (type double) and add them to a total until the number -1 is entered The - 1 is not added to the total. Write some instructions which will read a series of numbers (type double) and add them to a total until the character control-d is entered. Write 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