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
You must keep track of some data. Your options are: (1) A linked-list maintained in sorted order. (2) A linked-list of unsorted
ladessa [460]

Answer:

Question was incomplete and continued the question

For each of the following scenarios, which of these choices would be best? Explain your answer.

BST

Sorted Array

Un-sorted Array

a) The records are guaranteed to arrive already sorted from lowest to highest (i.e., whenever a record is inserted, its key value will always be greater than that of the last record inserted). A total of 1000 inserts will be interspersed with 1000 searches.

b) The records arrive with values having a uniform random distribution (so the BST is likely to be well balanced). 1,000,000 insertions are performed, followed by 10 searches.

Explanation:

Answer for a: Un-sorted array or Un-sorted linked list : as mentioned in the question itself that the records are arriving in the sorted order and search will not be O(log n) and insert will be not be O(n).

Answer for b : Un-sorted array or Un-sorted linkedlist : Number of the items to be inserted is already known which is 1,000,000 but it is very high and at the same time search is low. Unsorted array or Unsorted linked list will be best option here.

7 0
3 years ago
Matthew is working to select an authentication method for his company that will support REST as well as many web-based and mobil
vitfil [10]

Answer:

C) OpenID Connect

Explanation:

The best option is OpenID Connect because is based in OAuth, and supports multiple web based and mobile clients, and supports REST.

With OAuth, we cannot make any user authentication just provide a token to access data.

RADIUS is a networking protocol, and Shibboleth is a single sign-on log-in system for computer networks and the Internet, both not support REST.

6 0
3 years ago
Inheritance enables an object, called a _____, to derive one or more of its attributes from a parent.
jarptica [38.1K]

Answer:

The answer is C.) child

I hope this helps! ^-^

6 0
2 years ago
What software is my teacher using to do this and how can i stop her from doing this
aliina [53]

Answer:

I’m not sure if you can only teachers can acess that

Explanation:

7 0
3 years ago
Read 2 more answers
Which of the following is the best example of an installation issue
Tasya [4]

Answer:

A user made an error while trying to set up a software program.

6 0
3 years ago
Read 2 more answers
Other questions:
  • How can investors receive compounding returns? A: by selecting a savings account that has a higher interest rate B: by investing
    9·2 answers
  • Ancestor(X,father(X)) and ancestor(david,george) is they unify or not
    11·1 answer
  • An organization is trying to decide which type of access control is most appropriate for the network. The current access control
    12·1 answer
  • I'm trying to network two laptops together using ethernet cable but it isn't working. Why isn't it working
    9·1 answer
  • VEE Physics 2006 E.C
    7·1 answer
  • A typical day in programming and software development would involve
    7·1 answer
  • Find the unknown quantities
    12·1 answer
  • How does information promote cooperation and Industry please explain​
    6·1 answer
  • Which emerging technologies will have more injury on our day to day country &amp; How?​
    10·1 answer
  • What type of html list will automatically place a list marker, or bullet point, indicator in front of each item? group of answer
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!