recategorized by
4,217 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
recategorized by

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.
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 votes
–1 votes
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.
Answer:

Related questions

5 votes
5 votes
2 answers
2
Arjun asked Apr 22, 2018
8,442 views
Consider the following program{ int x=1; printf("%d",(*char(char*)&x)); }Assuming required header files are included and if the machine in which this program is executed ...
5 votes
5 votes
3 answers
3
Arjun asked Apr 22, 2018
5,573 views
Consider the following declaration :structaddr { char city[10]; char street[30]; int pin; }; struct { char name[30]; int gender; struct addr locate; } person, *kd = &pers...
1 votes
1 votes
2 answers
4