Ask Question
24 May, 00:28

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. 24 May, 01:56
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers