InterviewSolution
Saved Bookmarks
| 1. |
The following is a function of some class which checks if a positive integer is an Armstrong number by returning true or false. (A number is said to be Armstrong of the sum of the cubes of all its digits is equal to the original number.) The function does not use modulus (%) operator to extract digit. There are some places in the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which may be replaced by a statement/expression so that the function works properly.boolean ArmstrongNum(int N) { int sum = ?1?; int num= N; while(num>0) { int f=num/10; int s= ?2?; int digit = num-s; sum+=?3?; num= ?4?; } if(?5?) return true; else return false; } (i) What is the statement or expression at ?1? (ii) What is the statement or expression at ?2?(iii) What is the statement or expression at ?3?(iv) What is the statement or expression at ?4? (v) What is the statement or expression at ?5? |
|
Answer» (i) 0 (ii) 0 (iii) (f * f * f); (iv) num/10; (v) s == num |
|