What is the output of the programvoid main(){int i,j,k,n=5;clrscr();for(i=5;i>0;i--){j=1<i;k=n&j;k==0?printf("0"):printf("1");}getch();}A. 00011B. 11110C. 11001D. 11100

B

This question is related to Oracle Interview

Showing Answers 1 - 7 of 7 Answers

Aswini

  • Jun 29th, 2006
 

B 11110

  Was this answer useful?  Yes

aniljoo

  • Feb 12th, 2007
 

answer should be 11110

  Was this answer useful?  Yes

Although we may think that the code contains errors but its logical approach,

We have a for-loop in which i is initialized to 5. The value of j =1 if 1<i i.e. it is valid for i=5,4,3,2 and the truth value is tored as 1 in the variable j.

now,k has the n&j i.e. the & operator is used to check the boolean truth value and is stored in the variable-k. If k=1 then,it prints 1 i.e. seen upto number 2 of i.


Thus,answer is B.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions