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
Based on current and upcoming gaming technologies, what changes do you expect to see in the next generation of gaming consoles?
damaskus [11]
Better graphics getting 1080 p easily running on 240 frames and a higher storage so then you could have more games on the console
4 0
3 years ago
Once Raul selects a technology solution, he has completed the process. <br> a. True<br> b. False
romanna [79]
The answer is true because choosing a technology solution is the last step
7 0
3 years ago
Read 2 more answers
How do we distinguish between remote and local information sources? give an example of each source? i'll give brainliest answer
kirill [66]

A local server means that you have a server setup on your current machine. A remote server is ran on a different machine

7 0
2 years ago
Jim has listed stages of the product life cycle in his presentation which slide element can you use to make the items in the lis
IgorC [24]

jim can use bullet points.

  • this
  • is
  • an
  • example
  • of
  • bullet
  • points!
8 0
3 years ago
To<br> a<br> Question I<br> Explain why microsoft Excel is referred<br> preashent package -
ikadub [295]

Microsoft Excel is a spreadsheet program included in the Microsoft Office suite of applications. ... Spreadsheets present tables of values arranged in rows and columns that can be manipulated mathematically using both basic and complex arithmetic operations and functions.

.

6 0
2 years ago
Other questions:
  • Consider the provided C++ code in the main.cpp file: The function func2 has three parameters of type int, int, and double, say a
    8·1 answer
  • Whats your favorite sport between these options?
    12·2 answers
  • It chapter 2 pennywise
    13·1 answer
  • Write a program that does the following:
    11·1 answer
  • list = 7 # these many modified Fibonacci numbers. def fibonacci_gt(n, t1, t2): if n&lt;0: print("Incorrect input") elif n == 0:
    12·1 answer
  • A ____ is a statement specifying the condition(s) that must be true before the function is called.
    6·1 answer
  • You are given a 5-letter word (for example, abcde). Write a C-Program which outputs all possible unique 5 letter permutations of
    13·1 answer
  • Please help meeee , you will get 20 points
    9·2 answers
  • Apply the Fill - Teal, Accent 4, Soft Bevel text effect (the 5th
    12·1 answer
  • A laptop can be kept on palm to work. [true/false) ​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!