Professional Documents
Culture Documents
Question New
Question New
Question New
Dated:
Assignment:2 2018/PLT
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 if
the sum of the cubes of all its digits is equal to the original number
.)The functiondoes not use modulus (%) operator to extract digit. There are some places in thecode 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?
Question 2:
A palindrome no is a number which read same from forward and reverse. For example 151, 232, 4334 etc. A mathematician as
followed some other process for finding a p[alindrome of a number having two or more digits as follows:
Step 1 : Reverse the digits of the original number.
Step 2 : add the reverse number and the original number to get a new number.
Step 3 : If the new number is a palindrome number, means the number is found as palindrome otherwise repeat all above steps by
taking new no as the original number till a palindrome number is not obtained. Repeat your process upto maximum of 15 steps.
For example : Input: num=78
Step 1 Step 2 step 3 step4
Number: 78 165 726 1353
Reverse: 87 561 726 3531
--- ---- ---- -----
Sum: 165 726 1353 4884
(new number)-- ---- ----- -----
Output: num=78 its palindrome number =4884 and found in step 4