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

what does TVET stand for?​
f(x)=2x-8 g(x)=x^(2) Find a value of x such that fg(x)=0.
Consider two accounts, which both have an initial deposit of $5,000 at 2.5% interest for 11 years. Find the difference in the total amounts of the accounts when
HELP PLEASE! REAL AWNSERS ONLY!
HELPPPPPPPPPP PLEASEEEEEEEE!!!!!!
identify Cl,Br,I ions in nacl,nabr,nai solutions respectively practical
A compound x on treating with dilute HCl release a gas which turns milkey metal x is used in glavinazion of iron articles explain the extraction of metal x from
Why are chinampas is the best Aztec invention
What is the theme for Kruppel Engels
40 mL 30 mL 20 mL 10 mL 30 mL 20 mL 40 mL These graduated cylinders are the same size and there is the same amount of water in each. If the red 30 mL 20 mL marb