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]
2 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]2 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 heading function is the biggest?<br> 1. h1<br> 2. h2<br> 3. h3
sattari [20]

Answer:

h3

Explanation:

sub to Thicc Panda on YT

6 0
3 years ago
Read 2 more answers
Maria's manager asked her to print a certain document for their meeting. It took her so long to find the file that she was late
Hoochie [10]

hey let me and sans help. . . . .hmmm. . .

sans said create a word-processing document that lists where she has saved files.

9 0
3 years ago
Read 2 more answers
Which results are expected in a personality test but not a skills assessment?
dimaraw [331]

Answer:

openness, conscientiousness, extraversion

Explanation:

A personality test is defined as a test that is used to assess the human personality. It is designed as the techniques to measure characteristics patterns of the traits that various people shows at different situations or environments.

A skill assessment test is used to test the abilities and the skill sets of people to perform a particular tasks given to them. It is measuring the knowledge and skills of a person.

The personality test are carried out to test how human behave and what traits they show in certain conditions. Thus openness, extra version and conscientiousness are some of the traits that people usually shows in a personality test. Thus they are the results that are expected by an individual of a personality test.

6 0
2 years ago
. A store and forward switching strategy is generally used in ______ switched network.
xz_007 [3.2K]
The answer would be a
5 0
3 years ago
Read 2 more answers
QN, 3. Write the working principle of computer.<br>​
Gnom [1K]

Answer:

A computer is a machine made up of parts for the hardware and software. Based on the instructions given, a computer receives data through an input unit and sends it back through an output system after it processes the data. The input devices of a computer are used to get the input data.

7 0
2 years ago
Other questions:
  • How would I view the ruler on my document if it was not visible
    9·1 answer
  • The Transmission Control Protocol (TCP) splits each message into multiple packets. It's possible for packets from the same messa
    10·1 answer
  • You have just provided the identification number that associates your new software purchase with the mobile device on which you
    7·1 answer
  • How does LinkedIn differ from other popular social media platforms? What are the similarities?
    6·1 answer
  • What is mendix about?
    10·1 answer
  • Of the measures of feasibility in the accompanying figure, ____ considers points such as "Does the proposed platform have suffic
    8·1 answer
  • All portions, to include subject, title, paragraphs, sub-paragraphs, graphics, tables, charts, and bullet statements, must be pr
    12·1 answer
  • Use Spreadsheet Functions and Formulas
    6·1 answer
  • A good information that contains the facts necessary for decision makers to solve a problem is characterized by the __________.
    15·2 answers
  • As a technical support rep, michael is responding to a customer's question sent to him via e-mail. what should michael's first t
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!