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
True or false. Embedding only part of a font is called presetting.
svetoff [14.1K]
The answer is actually false. Embedding only part of a font is called Subsetting. 
8 0
4 years ago
Cable Internet access can be described with which feature?
Alekssandra [29.7K]

Answer:

what issue do you think are important in our life

7 0
3 years ago
Read 2 more answers
G i r l s o n l y j o i n <br> id= ons jcuv jke
Katyanochek1 [597]

Answer:

nooooooo

1.1431586352

4 0
3 years ago
Read 2 more answers
What did basic elements of music look like in the Twentieth Century period?
Alexandra [31]

Answer:

I just want my 5 point lol sorry hope you get your answer

Explanation:

get terraria

5 0
3 years ago
What is the purpose of the print area feature​
Otrada [13]

Answer: The Print Area function in Excel allows you to print part of a spreadsheet rather than the full sheet

Explanation:

3 0
3 years ago
Other questions:
  • Which of the following is a goal of paraphrasing​
    12·1 answer
  • A user reports that she can't access the new server used in the accounting department. you check the problem and find out that h
    9·1 answer
  • Your marketing director at ABC Marketing Agency would like to set up an email campaign that will use personalization to referenc
    5·1 answer
  • What are some options available in the Spelling and Grammar Checker? Check all that apply. Change and Change All Redo and Repeat
    15·2 answers
  • What is the data and information with example? ​
    9·1 answer
  • I had tried to turn on Linux on the Chromebook but it's not working
    11·2 answers
  • Select the correct answer from each drop-down menu.
    7·1 answer
  • he superclass Student contains: a constructor that accepts a String corresponding to the name of the school the student attends
    15·1 answer
  • What is closeable interface in java.
    12·1 answer
  • The following Python statement instructs the program to open a file for input.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!