Question: please solve QUESTION 2 in java or any other programming language. use the same numbers 1. The mysterious 4 -digit number 6174. The algorithm: 1.





1. The mysterious 4 -digit number 6174. The algorithm: 1. Chose a 4-digits number, digits are not all the same, not 1111,2222 ,... 2. Exctract its digits. 3. Rearrange the digits to get the largest and smallest numbers these digits can mak 4. Subtract the smallest number from the largest to get a new number. 5. If the new number is different from 6174 , repeat the operation. You will get there after a finite itertions. 6. Count the iterations. For example; n=2345, digits are 2,3,4,5 max number is, max-5432, min number is, min=2345, n=maxmin=54322345=3087 n=3087, and start over... 10 rem JBASIC 12cls 15 dis = dates 0: tis = times 0 18 pint "The mysterious 4 digit number 6174 20rammax of iterations 20 25 print 30 input "enter 4 -digit number: "in 32k=0 : dim nu(100) 35anrc=0:x=0 45 a m: man=0: mx=0 48rem show digits 50rl=(nmod10) 55 c-ct1: nr(c)=r1 60nn/10:n=int(a) 70 if int (n)>>>cd, (max number) 195remmn,mx minimum, maximum number 200 for j=1 to c1 210 for j=i+1 to c 220 if mn(j)>n( (i) then b=mn(i):mn(i)=mn(j):mn(j)=b 225 if mx(i)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
