Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please solve this question in java or any other programming language that u are more comfortable. use the same numbers like in the example. 1.
please solve this question in java or any other programming language that u are more comfortable. use the same numbers like in the example.
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. Exatact its digits. 3. Rearrange the digits to get the largest and smallest numbers these digits can make. 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 iterations. 6. Count the iterations. For example; n=23.45, 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 18 print "The mysterious 4 digit number 6174 " 20 rem max of iterations 20 25 print 30 input "enter 4-digit number: "; n 32k=0 : dim nr(100) 35 arnec =0:rv=0 45 a n:mn=0:mx=0 48 rem show digits 50r=(nmod10) 55c=c+1:nr(c)=r1 60nnn/10:n= int(n) 70 if int (n) >0 then goto 50 95 print " digits are:"; 100 for i=1 to c 110 print nar(i):"," 120mn(i)=nr(i):mx(i)=n(i) 125 next 130 remn number and revense 140 for i=1 to C 150rv=rv+nr(0)(10)(c1)) 160 next 190 rem sort the digits min-max, aa>b>c>d, (max number) 195 rem mn,mx minimum, maximum number 200 for i=1 to c1 210 for j=i+1 to c 220 if mn(i)>nr(j) 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started