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

Which statement describes the structure of DNA? A. a single strand of amino acids B. a single strand of nucleotides C. a double strand of nucleotides D. a doubl
​ 5y−4x=−7 2y+4x=14 ​ x=____ equals y=____ equals
At equilibrium, no chemical reactions take place. true or false
A budget surplus a. exists when government spending is greater than tax revenues. b. causes government debt to increase. c. occurs when the government has debt
what is less than 3/4 and larger than 1/4
Consider the equation -5(x+7)<-10. Write an inequality representing the solution for x
Thousands of Chinese men and women immigrated to North America during the last half the 19th century, many of them to work on the construction of American railr
PLEASE ANSWER FAST I NEED ANSWER QUICK What is the value of m∠a + m∠b ? A) 34° B) 56° C) 90° D) 180°
What was Babylonian religion like
Please help meeeeeeee