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
Binary Search:<br><br><br> 2 6 15 42 55 89 111 256
fgiga [73]

Answer:

2 =  10

6 = 110

15 = 1111

42 = 101010

55 = 110111

89 = 1011001

111 = 1101111

256 = 100000000

8 0
3 years ago
For a loop counter, the appropriate data type would be:
BigorU [14]

Answer:a) int

Explanation: Loop counter is the kind of program that has the major function of counting the start value to the destination value in the form of integer.The integer is used for counting the values in a particular loop is known as the loop control variable.Therefore the accurate datatype for the loop counter to count the values should be of int type.

8 0
3 years ago
Please select the word from the list that best fits the definition<br><br> Plagiarism
Pachacha [2.7K]
The practice of taking someone else's work or ideas and passing them off as one's own.
5 0
1 year ago
Read 2 more answers
Which one of these are a valid IPv4 address?
Harman [31]

Answer:

1.1.1.1, 54.45.43.54, and 255.255.255.0

3 0
1 year ago
Danny is editing the text content of a single page on a website he created a year ago. What part of the tag would he have to upd
Verdich [7]
<h2>"<lastmod>" is the right choice for the given scenario</h2>

Explanation:

<update> This tag does not belong to <URL> tag of the site map. Hence this option goes invalid.

<lastmod> This gives details of the date and time when the website content was changed. It will be in "W3C Date time format". This may omit time at times. This is the write answer.

<loc> This contains the URL of the web page.

<changefreq>: How frequently the "web page is likely to get modified". The  values which it accepts are: "monthly, always , daily , weekly ,hourly, yearly , never"

5 0
3 years ago
Other questions:
  • If you were to conduct an Internet search on vegetarian restaurants, which of the following searches would be the best
    7·1 answer
  • Mobile devices typically come pre installed with standard apps like web browsers , media players, and mapping programs true or f
    9·1 answer
  • Which of the following is needed if a computer with the IP address 172.31.210.10/24 wants to communicate with a computer with th
    5·1 answer
  • The code segment below uses the procedure IsPartOf (list, item), which returns true if item appears in list and returns false ot
    13·1 answer
  • You are configuring a switch that has three hosts attached to FastEthernet 0/2 through 0/4. All three hosts are part of a public
    10·1 answer
  • Suppose that we have a set of activities to schedule among a large number of lecture halls, where any activity can take place in
    8·1 answer
  • The data in a database management system that identifies the names of​ tables, fields in each​ table, and the properties of each
    13·2 answers
  • Write a program that uses an initializer list to store the following set of numbers in an array named nums. Then, print the arra
    10·2 answers
  • Write a Java program that launches 1000 threads. Each thread adds 1 to a variable sum that initially is 0. You need to pass sum
    11·1 answer
  • PLEASE HELP! WILL MARK AS BRAINLIEST!
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!