in Programming in C recategorized by
4,249 views
5 votes
5 votes

Consider the following C program:

main()
{
float sum= 0.0, j=1.0,i=2.0;
while(i/j>0.001){
    j=j+1;
    sum=sum+i/j;
    printf("%f/n", sum);
  }
}
  1. $0$ - $9$ lines of output
  2. $10$ - $19$ lines out output
  3. $20$ - $29$ lines of output
  4. More than $29$ lines of output
in Programming in C recategorized by
by
4.2k views

1 comment

No, D) is correct.

See this question: https://gateoverflow.in/52437/isro2014-38

Same question but here in this question j is incremented as j = j +1 but there j was incremented as j = j + j.

1
1

4 Answers

12 votes
12 votes
Here while loop runs till (i/j) becomes equal to 0.001.

Now, 0.001=(1/1000)

So, the while loop runs till (i/j) = (1/1000)

=> i*1000=j

Now i =2 and j=1

So,the while loop runs till j becomes equal to 2000.

So, the output will have more or less 2000 lines.

Hence option D is correct.
edited by

1 comment

I think its $10,000$ times.
0
0
4 votes
4 votes

Here , i is fixed ,only j increases by 1. So the inequality equation becomes 2.0 / j > 0.001 => j < 2000 . Therefore the loop runs for 1999 times.

Option (D) is correct.

1 comment

$i=2.0 , j=1.0$

while condition false at $i/j <= 0.001$

$i<= 0.001*j$

$j>=10^3 * 2$

So, at $j=10^3 * 2$ condition false and loop executes for $1999$ times.(same as Lines of Output)
0
0
0 votes
0 votes
Option (B) is correct.

1 comment

No, D) is correct.

See this question: https://gateoverflow.in/52437/isro2014-38

Same question but here in this question j is incremented as j = j +1 but there j was incremented as j = j + j.

1
1
–1 vote
–1 vote
B option .there is a series of log n i.e 2*(1+1/2+1/3+1/4 ------ 1/n) here n is  512. as (1/1024 <.001) loop will terminate. now                2* (log 512)= 2*9=18 hence 1-18 loop will iterate so.

2 Comments

but value of i is not changing in the loop and j is incremented by 1 only
0
0
edited by
now i got,my explanation was wrong your are correct.
0
0
Answer:

Related questions