Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

please solve QUESTION 2 in java or any other programming language. use the same numbers
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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)>b>c>d, (max number) 195remmn increase digits, mx - decrease digits 200 for i=1 to c1 210 for j=i+1 to c 220 if mn(j)n(j) then d=mx(i):mx(i)=mx(j):mx(i)=d Home Insert Draw Design Loyout Roferences Mallings Roviow Viow minimum number is 279 maximum number is 972 mxmn=693 digits are: 3,9,6, minimum number is 369 moximum number is 963 mxmn=594 digits are: 4,9,5, minimum number is 459 maximum number is 954 mxmn=495 Nr. of iterations =4 end the program (y)y start at, Jan 05, 2023, 19:58:44 end at, Jan05,2023,19:58:50 rood bye! (33)<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is voice over internet ( voip )

Answered: 1 week ago