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
• The length of time between water level measurements/ control adjustments is DT. • If the water level drops to the bottom of th
VikaD [51]

Answer:

Water level control systems are used to control the level and flow of water circulation systems for a variety of processes. The device that performs the controlling action is a valve which is attached to a controller whose main objective is to maintain a desired set point level as well as accept a new one desired by the control engineer.Fuzzy logic is widely used in the control of many processes, including that of the control of the water level in a tank.

DESIGN APPROACH

The system consists of a tank, a valve, a fuzzy logic controller, the inputs (level, rate) and the outputs (scopes).The tank system is modelled using SIMULINK and consists of two pipes; one flowing in and the other flowing out denoted by inflow and outflow respectively. The fuzzy controller controls the valve that changes the diameter of the inflow pipe but the outflow rate depends on the diameter of the outflow pipe (which is constant) and the pressure ( which depends on the level ) of the water. Thus, by keeping the water level at the desired set-point, we ensure that the tank works properly.

Water Level Control in a Tank PID(s) PID Controller Mux WATER TANK VALVE Mux2 S-Function SwitchSubsystem Mux tank 2 Sum1

The watertank design model, shown in the figure below, models a feedback loop for regulating the water level in a water tank. The Controller block contains the first-order compensator to be tuned.

The simulink model of the control system is

mdl = 'watertank_comp_design';

open_system(mdl);

Voltage for H 10-C- (++ Input Output Desired Water Level Controller Scope Water-Tank Systemm

The Water Tank subsystem models the water-tank dynamics. Water enters the tank from the top at a rate proportional to the voltage, V, applied to the pump. The water leaves through an opening in the tank base at a rate that is proportional to the square root of the water height, H, in the tank. The presence of the square root in the water flow rate makes the plant nonlinear.

Simulation

Simulate controller response with periodic changes in the setpoint of the water level. When you run the model, the Rule Viewer updates dynamically to show which rule the fuzzy controller is using to set the flow rate.

sim('sltankrule',100);

bdclose('sltankrule');

4 0
4 years ago
How long does a seller have to ship an item on offerup
ra1l [238]

They have up to six days to ship the item after it has been purchased via either the Buy Now option or them accepting an offer.

7 0
2 years ago
what are the three parts to physical security standards for various types of army equipment and the risk level
zzz [600]

The three parts to physical security standards for various types of army equipment and the risk level is access control, surveillance, and security testing.

<h3>Further explanation</h3>

Physical security is the part of security concerned with physical measures designed to protect the assets and facilities of the organization.  

The three parts to physical security standards for various types of army equipment and the risk level is access control, surveillance, and security testing.

Access control is a security technique in which regulates who/what can view/use resources in a computing environment. The example of physical access control is the locks, badge system, and security guard.

Surveillance is the condition in which the architects seek to build spaces that are more open to security personnel and authorized users. It is also the continuous monitoring of, for example, the disease occurrence. The example of surveillance is Closed-circuit television cameras (CCTV) placed in the streets.

Security testing is the evaluation and testing the information security of hardware, software, networks, and IT environment. Error handling and specific risky functionalities are examples of security testing

<h3>Learn more</h3>

1. Learn more about the security practice in electronic banking brainly.com/question/7668763

 

<h3>Answer details</h3>

Grade:  9

Subject: Computers and Technology

Chapter:  Physical security standards

Keywords:  physical security, access control, surveillance, security testing

3 0
3 years ago
Explain what the problems with the implementation of the function are, and show a way to fix them.// return true if two C string
Nataly [62]

Answer:

The code is not dereferencing the pointers. You have to place an asterisk in front of the pointer to read the value the pointer points to.

Explanation:

So "if (str1 != str2)" must be "if (*str1 != *str2)".

likewise:

   while (*str1 != 0 && *str2 != 0)

and

     result = (*str1 == *str2);

7 0
3 years ago
Spam and i report
defon

Answer:

option d is the correct answer

8 0
3 years ago
Read 2 more answers
Other questions:
  • Consider the partially-filled array named a. What does the following loop do? (cin is a Scanner object)
    12·1 answer
  • I need help with this​
    7·1 answer
  • If you want to insert a column into an existing table what would you do
    11·1 answer
  • In the United States, everyone is guaranteed work true or false
    13·1 answer
  • Jane, a marketing manager for the Grocery SuperStore retail chain, fired up a computer program that gave her ready access to inf
    6·1 answer
  • What is key for evaluating internal controls such as human resources, logistics, information technology, risk, legal, marketing
    11·1 answer
  • Was Google right to have entered the Chinese market the way it did? Did Googleâs mission compel it to create Google.cn? What spe
    9·1 answer
  • Ashton assigned a string value to a variable. Which program statement should he use?
    7·1 answer
  • As a basic user of SAP Business One, which feature of the application do you like most? Elaborate on your answer.
    15·1 answer
  • From which latin word the word computer is derived​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!