How to implement a program that displays all four-digit numbers abcd for which the following conditions are true:
a,b,c,d- different numbers;a*b = c*d
How to implement a program that displays all four-digit numbers abcd for which the following conditions are true:
a,b,c,d - different numbers;a*b = c*dAlgorithm.
In principle, the search for 10,000 numbers on modern technology is very fast, but the teacher clearly needs something else. Here is an example of a blunt search for each digit.
program fn; type digit = 0 .. 9; var i1, i2, i3, i4 : digit; s2, s3, s4: set of digit; begin for i1 := 0 to 9 do begin s2 := [0..9] - [i1]; for i2 := 0 to 9 do begin (* сумма пары цифр не может быть <3 (1+2,0+3) и >15(7+8,9+6) *) if not (i2 in s2) or (i1+i2 < 3) or (i1+i2 > 15) then continue; s3 := s2 - [i2]; for i3 := 0 to 9 do begin if (not i3 in s3) or (i3 > i1 + i2) then continue; s4 := s3 - [i3]; for i4 := 0 to 9 do if (i4 in s4) and (i1+i2 = i3+i4) then writeln(i1:1, i2:1, i3:1, i4:1); end end end end. Source: https://ru.stackoverflow.com/questions/73688/
All Articles