1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Katen [24]
3 years ago
13

Write a program that reads numbers from scanf (keyboard) and then sums them, stopping when 0 has been entered. Construct three v

ersions of this program, using the while, do-while, and forloops.
Computers and Technology
1 answer:
almond37 [142]3 years ago
4 0

Answer:

For loop Version:

#include <stdio.h>

int main()

{

   int number, sum = 0;

   printf("Enter a positive integer: ");

   scanf("%d", &number);

   

   for (int i = 0; i <= number; i++) {

       if(number == 0)

           break;

       sum += number;

       

       printf("Enter a positive integer: ");

       scanf("%d", &number);

   }

   printf("Sum is: %d", sum);

   return 0;

}

- - - - -

While Loop Version:

#include <stdio.h>

int main()

{

   int number, sum = 0, i = 0;

   printf("Enter a positive integer: ");

   scanf("%d", &number);

   

   while (number != 0) {

       sum += number;

       

       printf("Enter a positive integer: ");

       scanf("%d", &number);

   }

   printf("Sum is: %d", sum);

   return 0;

}

Do-while Loop Version:

#include <stdio.h>

int main()

{

   int number, sum = 0, i = 0;

   

   do {

       printf("Enter a positive integer: ");

       scanf("%d", &number);

       

       sum += number;

       

   } while (number != 0);

   printf("Sum is: %d", sum);

   return 0;

}

Explanation:

- Initialize the variables

- Ask the user for the numbers until the user enters 0

-  Calculate and print the sum

You might be interested in
Which statement is true about customizing presentation programs? A. You can add multiple animations to an object in a slide with
levacccp [35]

From all the given options, the correct statement about customizing presentation is (B) you can customize a pre-designed slide layout with the Slide Master.

The option (A) is false, because if you want to put animations on your slide objects, you need to go to the Animation tab, while option (C) is false because to view the animation that you assign to a slide object, you need to open the animation pane bar or go to slide show. Option (D) is false because you <em>can </em>make changes to the colors, fonts, and effects for pre-designed slide themes.

6 0
3 years ago
Read 2 more answers
The name for the instructions you write to a computer in a program
aliina [53]

Answer:

Code

Explanation:

The code is instructions that you can write yourself or download from online

4 0
2 years ago
Read 2 more answers
a. Show the output of the following program: 1: public class Test { 2: public static void main ( String [] args ) { 3: A a = new
faust18 [17]

Answer:

See attached file.

Explanation:

See attached file.

Download txt
3 0
3 years ago
How far away in hours is georgia from oklahoma?
Allushta [10]

Answer: car 15h 34m

hope this helps

3 0
3 years ago
Read 2 more answers
Companies typically like to design scorecards that fit their business and industry. As a result there are now software applicati
Leya [2.2K]

Answer:

Web-based balanced scorecard applications are sometimes referred to as performance dashboards.

Explanation:

Performance dashboards are common management tools used to gauge performance and enable business people to measure, monitor, and manage the key activities and processes needed to achieve business goals.

6 0
3 years ago
Other questions:
  • In programming, what is a floating-point number?<br>​
    7·1 answer
  • _______ are unprocessed facts that a computer feeds on.
    5·1 answer
  • Assume that name and age have been declared suitably for storing names (like "Abdullah", "Alexandra" and "Zoe") and ages respect
    8·1 answer
  • In the windows firewall, any rules preceded by a __________ checkmark have not been enabled. black gray green red
    13·1 answer
  • What is the output of the following program? #include using namespace std; class TestClass { private: int val; void showVal() {
    5·1 answer
  • What emphasizes extensive user involvement in the rapid and evolutionary construction of working prototypes of a system to accel
    15·1 answer
  • If the computer has an encrypted drive, a ____ acquisition is done if the password or passphrase is available. a. passive b. sta
    8·1 answer
  • when using presentation software, which menu can you use to duplicate a slide to use as a template for a new slide?
    14·1 answer
  • ITS A VOTE I NEED HELP
    12·1 answer
  • How can you relate the careers in Finance as BSIS students?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!