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

when two air masses of different temperatures come together, they can cause a
Which animal has tracheae but no lungs for respiration? A. cardinal B. grasshopper C. toad D. tuna
is skin cancer sex linked
Bacteria are very small single-celled organisms that lack a nucleus. Although bacterial cells are less complex than the cells that make up the human body, bacte
there are 798 calories in six 10-ounce bottles of apple juice. How many calories are there in one 10-ounce bottle of apple juice
If 3t − 7 = 5t , then 6t = how do you solve this
x+y=10 x-y=20 how do you solving systems of equations with elimination
Describe three properties of a frozen fruit bar including its state of matter.
how do you convert units within a measurement system
Given CDEFG ≌ HIJKL and CD = 12, DE = 13, EF = 10, FG = 11, and GC = 8, what is HI? Does anyone Know ?