Ask Question
15 May, 05:46

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);

+2
Answers (1)
  1. 15 May, 06:39
    0
    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.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What is wrong with the following C+ + code? How would you fix it? int sum; for (int i=0; i ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers