Ask Question
27 January, 02:32

Show the exact output of the following codesegments: (a) for (x=0; x<20; x=x+2) cout<< x << ' '; cout<0; i = i/2; ) cout<< i;

+5
Answers (1)
  1. A
    27 January, 02:51
    0
    a)

    for (x=0; x<20; x=x+2)

    cout<< x << ' ';

    cout<< endl;

    Output

    0 2 4 6 8 10 12 14 16 18

    In this code we are initialing x with 0, check if it is less than 20, then printing the value 0.

    Then we increment x value with 2 and check and print again until the x value tends to be equal or more than 20.

    C+ + program for verifying

    #include

    using namespace std;

    int main ()

    {

    int x;

    for (x=0; x<20; x=x+2)

    cout<< x << ' ';

    cout<< endl;

    return 0;

    }

    Output

    0 2 4 6 8 10 12 14 16 18

    (You can check on any ide for confirmation)

    b)

    i=10;

    for (; i>0; i = i/2; )

    cout<< i;

    This code will produce error expected ') ' before '; ' token

    for (; i>0; i = i/2; )

    because for loop consist three parameters and in this loop there are 4 parameters.

    If we remove semicolon after i/2,

    for (; i>0; i = i/2)

    then it will produce an output.

    10 5 2 1

    C+ + program for verifying

    #include

    using namespace std;

    int main () {

    int i=10;

    for (; i>0; i = i/2; )

    cout<< i;

    return 0;

    }

    Output

    Error-expected ') ' before '; ' token

    for (; i>0; i = i/2; )
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Show the exact output of the following codesegments: (a) for (x=0; x ...” 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
Sign In
Ask Question