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
omeli [17]
3 years ago
14

program that reads numbers from scanf (keyboard) and then sums them, stopping when 0 has been entered. Construct three versions

of this program, using the while, do-while, and for loops.
Computers and Technology
1 answer:
Alex17521 [72]3 years ago
7 0

Answer:

Explanation:

I'm going to write three examples in C language:

int main() {

   int n, i, sum = 0;

   printf("Enter the number: ");

   scanf("%d", &n);

   for (i = 1; i <= n; ++i) {

       sum += i;

   }

   printf("Sum = %d", sum);

   return 0;

}

int main() {

   int n, i, sum = 0;

   printf("Enter a number: ");

   scanf("%d", &n);

   i = 1;

   while (i <= n) {

       sum += i;

       ++i;

   }

   printf("Sum = %d", sum);

   return 0;

}

int main() {

   int n, i, sum = 0;

   do {

       printf("Enter a number: ");

       scanf("%d", &n);

   } while (n <= 0);

   for (i = 1; i <= n; ++i) {

       sum += i;

   }

   printf("Sum = %d", sum);

   return 0;

}

You might be interested in
.vx*^#♡■●;(<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eaceaa">[email&#160;protected]</a>(;=!^$□◇○(
Stells [14]

Answer:??

Explanation:what is that suppose to mean?

please give me a brainiest if you don't mind

4 0
3 years ago
Harvey is creating a presentation for his school project. He wants to have the same look on all the slides of his presentation.
Misha Larkins [42]
He should use PowerPoint and the design should be feathered
8 0
3 years ago
Computer files containing nothing but printable characters are called ____ files.
natali 33 [55]
Computer files containing nothing but printable characters are called text files<span>.</span>
7 0
3 years ago
Which pair of properties apply to both sound and electromagnetic waves?
Alex73 [517]
Both waves can have interference, reflection, and diffraction.

Wave interference is a phenomenon that occurs when two waves meet while traveling along the same medium. The interference of waves causes the medium to take on a shape that results from the net effect of the two individual waves upon the particles of the medium.

Wave reflection happens when a wave reaches the boundary between one medium and another medium, a portion of the wave undergoes reflection and a portion of the wave undergoes transmission across the boundary.

Wave diffraction<span> involves a change in direction of waves as they pass through an opening or around a barrier in their path.<span> </span></span>
3 0
3 years ago
Read 2 more answers
Write a program consisting of: a. A function named right Triangle() that accepts the lengths of two sides of a right triangle as
Lunna [17]

Answer:

The java program is as follows.

import java.lang.*;

public class Triangle

{

   //variables to hold sides of a triangle

   static double height;

   static double base;

   static double hypo;

   //method to compute hypotenuse

   static double rightTriangle(double h, double b)

   {

       return Math.sqrt(h*h + b*b);

   }

public static void main(String[] args) {

    height = 4;

    base = 3;

    hypo = rightTriangle(height, base);

 System.out.printf("The hypotenuse of the right-angled triangle is %.4f", hypo);

}

}

OUTPUT

The hypotenuse of the right-angled triangle is 5.0000

Explanation:

1. The variables to hold all the three sides of a triangle are declared as double. The variables are declared at class level and hence, declared with keyword static.

2. The method, rightTriangle() takes the height and base of a triangle and computes and returns the value of the hypotenuse. The square root of the sum of both the sides is obtained using Math.sqrt() method.

3. The method, rightTriangle(), is also declared static since it is called inside the main() method which is a static method.

4. Inside main(), the method, rightTriangle() is called and takes the height and base variables are parameters. These variables are initialized inside main().

5. The value returned by the method, rightTriangle(), is assigned to the variable, hypo.

6. The value of the hypotenuse of the triangle which is stored in the variable, hypo, is displayed to the user.

7. The value of the hypotenuse is displayed with 4 decimal places which is done using printf() method and %.4f format specifier. The number 4 can be changed to any number, depending upon the decimal places required.

8. In java, all the code is written inside a class.

9. The name of the program is same as the name of the class having the main() method.

10. The class having the main() method is declared public.

11. All the variables declared outside main() and inside another method, are local to that particular method. While the variables declared outside main() and inside class are always declared static in java.

4 0
3 years ago
Other questions:
  • Assume that grade is a variable whose value is a letter grade-- any one of the following letters: 'A', 'B', 'C', 'D', 'E', 'F',
    9·1 answer
  • Your browsing the Internet and realize your browser is not responding which of the following will allow you to immediately exit
    14·2 answers
  • At a local marketing firm, Steve is the lead Web developer and is responsible for working with customers on their Web designs, d
    9·1 answer
  • Which value can be entered to cause the following code segment to display the message: "That number is acceptable." int number;
    11·1 answer
  • What is the most likely cause of a print job rendering the wrong colors on the output?
    14·1 answer
  • Write a SELECT statement that uses an aggregate window function to get the total amount of each order. Return these columns: The
    13·1 answer
  • Write a function named reverse_list that takes as a parameter a list and and reverses the order of the elements in that list. It
    12·1 answer
  • Hey, wanna pair our account on Brainly so we can share the perks? https://brainly.com/invite/8db681239ab5027e03b097bcded13755?ut
    15·2 answers
  • Which of the following calculations would evaluate to 12?
    7·1 answer
  • ________ take advantage of vulnerabilities in software. Group of answer choices Blended threats Bots Trojan horses Direct-propag
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!