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 of the following is not a driver of wireless growth? group of answer choices universal access to information and applicati
AysviL [449]

The invention of the micro hard drive is not a driver of wireless growth.

What is Hard Drive (HDD)?

A computer hard drive (also known as a hard disk or HDD) is a type of technology that stores your computer's operating system, applications, and data files such as documents, pictures, and music. The rest of your computer's components work together to display the applications and files stored on ones hard drive.

How does a Hard Drive (HDD) work?

A hard disk drive (HDD) is made up of a platter with data storage compartments. This information includes your operating system, applications, and any files that you have created. There's also an accuator arm that keeps moving across the platter to read or write the data. The platter spins as the accuator arm movements across it to speed up the process.

To learn more about Hard Drive (HDD), visit: brainly.com/question/27269845

#SPJ4

6 0
1 year ago
What are the advantage of an e-library​
Semmy [17]

Answer:

Makes it easier to read... summarize cite electronic versions of editions

3 0
1 year ago
A computer would do a better job than a human at solving lengthy, complex math problems. True False
Alborosie

Answer:

I would say true

Explanation:

Humans, by contrast, can master many things, from tying our shoes to cooking an omelet to solving complex math equations. The best AI hardly comes close to the incredible creativity and design of any human, and it’s an open question whether AI can ever become what its prophets claim. Second, when we make AI, we are basically copying our Creator.

8 0
3 years ago
Read 2 more answers
Which of the following items are typically included in a balanced budget A. The amount you earn in income
taurus [48]
D is the correct answer

8 0
3 years ago
What is communication​
IgorLugansk [536]

Answer:

it is when u talk to someone

6 0
3 years ago
Read 2 more answers
Other questions:
  • In addition to regular watch features, which two features are often found on smart watches?
    13·1 answer
  • Storing a value in a variable<br> Exponent<br> Variable<br> Assignment<br> Operator
    13·1 answer
  • Write a paragraph on the following topic.
    14·1 answer
  • In a registration database, Ross has tables for student, professor, classroom, class, class-hour. Since his campus has about 12,
    9·1 answer
  • DES: Group of answer choices A) is a commonly used symmetric encryption B) algorithm that was developed in the mid-C) 1970s was
    6·1 answer
  • Cual es la importancia de aplicar los pasos en el modelo de diseño en las actividades académicas?
    14·1 answer
  • What is the function of the NOS? Select all that apply.
    5·2 answers
  • A network administrator determines who may access network resources by assigning users
    10·1 answer
  • Que papel tuvo la innovación en la propagación de la telefonía móvil?​
    7·1 answer
  • New and just need help with C coding. I've tried if statements and it outputs the wrong number.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!