959 views
1 votes
1 votes

int main()
{
float sum, i = 1.0, j = 2.0;
while (i/j > 0.0625)
{
j = j + j;
printf("%f", i+j);
}
}

The number of times printf statement is executed is:

2 Answers

0 votes
0 votes
According to the above example, the loop will run 5 times as the values of i/j is 0.5, 0.25, 0.125 and 0.0625

respectively. But in the actual GATE 2019 question the values were swapped and according to that, the loop will run 3 times.
0 votes
0 votes

In the current question, printf will be executed 3 times.

In Gate 2019 question paper however, the original question was:

int main()
{

  float sum = 0.0, j = 1.0, i = 2.0;
  while (i / j > 0.0625)

  {


    j = j + j;

    sum = sum + i/j;
    printf("%f\n", sum);


  }

}

In the above scenario, printf will be executed 5 times

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
0 answers
2