GATE | GATE CS 2019 | Question 62
Consider the following C program:
#include <stdio.h> int main() { float sum = 0.0, j = 1.0, i = 2.0; while (i / j > 0.0625) { j = j + j; printf("%f\n", sum); }; return 0; } |
chevron_right
filter_none
The number of times variable sum will be printed When the above program is executed is _________ .
Note: This was Numerical Type question.
(A) 5
(B) 6
(C) 4
(D) 0
Answer: (A)
Explanation:
#include <stdio.h> int main() { float sum = 0.0, j = 1.0, i = 2.0; while (i / j > 0.0625) { j = j + j; printf("%f\n", sum); }; return 0; } |
chevron_right
filter_none
According to “while” loop,
Initially i = 2.0, j = 1.0 i / j = 2.0 / 1. 0 = 2.0 > 0.0625 j = j + j j = 2.0 printed sum = 0.0 Second time, i / j = 1 > 0.0625 j = 4 printed sum = 0.0 Third time, i / j = 0.5 > 0.0625 j = 8 printed sum = 0.0 Fourth time, i / j = 0.25 > 0.0625 j = 16 printed sum = 0.0 Fifth time, i / j = 0.125 > 0.0625 j = 32 printed sum = 0.0 Sixth time, i / j = 0.0625 = 0.0625 It violates the greater then condition. This time while loop will not execute.
So, option (A) is correct.
Recommended Posts:
- GATE | GATE CS 1999 | Question 36
- GATE | GATE CS Mock 2018 | Question 39
- Top 5 Topics for Each Section of GATE CS Syllabus
- How to prepare in Last 10 days to score high in GATE?
- Aptitude | GATE IT 2006 | Question 7
- Aptitude | GATE IT 2006 | Question 8
- GATE | GATE CS 2013 | Question 1
- GATE | GATE CS 2013 | Question 3
- GATE | GATE CS 2013 | Question 4
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 6
- GATE | GATE CS 2013 | Question 7
- GATE | GATE CS 2013 | Question 8
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 65



