Braley6210 Braley6210
  • 03-10-2019
  • Computers and Technology
contestada

What is wrong with the following C++ code? How would you fix it? int sum; for (int i=0; i<1000; ++i) sum += i; { printf("Sum of 0 to 999 is %d\n", sum);

Respuesta :

SerenaBochenek SerenaBochenek
  • 05-10-2019

Answer:

Correct code is:

int sum;

  for (int i=0; i<1000; ++i)

  sum += i;

      printf("Sum of 0 to 999 is %d\n", sum);

Explanation:

In the problem code there is a open curly open bracket after the sum+=1;.

This open bracket will give an To fix this code, we remove this bracket from  the given code.Then this code will calculate sum of all number from 0 to 999.And the last line of the code will print the sum.

Answer Link

Otras preguntas

1. In the figure at the right, it is given that PQ || TR. Find R 2 Q a. PS. b. QP 5 T 1.5 P s
What was one outcome of the spanish american war
What are the causes of diabetes mellitus
Which statement best characterizes prose writing
Why is it important to avoid looking like a US Tourist while in Spain?
MC Qu. 82 A design engineer wants to construct a sample... A design engineer wants to construct a sample mean chart for controlling the service life of a haloge
Hi please help me.. will give brainlest​
PLS help ASAP I DONT have time to answer this, it also detects if it’s right or wrong.
Asha bought a stapler for $6. She also bought some pens for $2 each. Asha did not spend more than $18 on the stapler and pens. Which inequality can be used to f
4. What was the main reason for sectional differences that existed in the United States in the early 1800s? M. The North, South, and West produced similar produ