Discussion
Consider the following program fragment i=6720; j=4; while (i%j)==0 { i=i/j; j=j+1; } On termination j will have the value
Answer: C
Correct answer: 9
Each pass divides i by j and then increases j:
| i | 6720 | 1680 | 336 | 56 | 8 | 1 |
|---|---|---|---|---|---|---|
| j | 4 | 5 | 6 | 7 | 8 | 9 |
At each step the division is exact, so the loop continues - until i is 1 and j is 9, where \(1 \bmod 9 = 1\) and the loop stops. j is then 9. (Note that 6720 = 4 × 5 × 6 × 7 × 8, which is what makes every division exact.)
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development