Saturday 9 March 2013

C/C++ Puzzles: PART - 26

Consider the C code given below.


#include<stdio.h>

int main( )
{
    int x=0;
    const int y=10;
    /* You Should only change the test condition of the while loop */
    while( )
    {
       printf("\nHello\n");
       x--;
    }
}


The task is to print the message "Hello" 10 times by filling the test condition of the while loop. But the following restrictions are applicable while filling the test condition.

1) You should only use the variables a and y.
2) Only operator can be used in the test condition.

Solution:-

If you haven't got the answer please select the Red Colour Field given below using your mouse.

    while(x+y)
    {
       printf("\nHello\n");
       x--;
    }



No comments:

Post a Comment