Programming in C - Decision Making and Looping

41. Consider the following program segment
i = 6720;
j = 4;
while (( i % j ) == 0)
{
  i = i / j ;
  j = j + 1;
}
on termination j will have the value

Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


42. The output of the following program is
main()
{
static int x[ ] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int I;
for (i = 2; i < 6; ++i )
x[ x[ i ] ] = x[ I ];
for( i =0; i < 8; ++i)
printf("%d", x[ I]);
}

Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


43. Consider the following program
main( )
{
int x = 2, y = 5;
 if (x < y)
 return ( x = x + y);
 else printf ("z1");
printf ("z2");
}
Choose the correct statements

Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


44. The for loop
 for( i=0; i<10; ++i)
 printf("%d", i & 1);
prints

  • Option : A
  • Explanation :
    The binary representation of odd numbers will have a 1 as the least significant digit. So, an odd number ANDed with 1, produces a 1.
    Even number end with 0. So. an even number ANDed with 1, produces a 0.
    This for loop generates even and odd numbers alternatively.
    So, it prints alternate 0's and 1's
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


45. Consider the program fragment
j = 2;
while ((i % j) ! = 0)
j = j + 1;
if (j < i) printf ("%d", j);
If i >= 2, then the value of j, will be printed only if

Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *