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
  • one
    Describe what conditions you make to resolve the issue? - Artem
  • one
    @tkoff Training question implies an independent solution attempt. - Nicolas Chabanovsky

2 answers 2

Algorithm.

  1. Let i be zero.
  2. Generate a four-digit number from i.
  3. Check the condition of the output number
  4. If the condition is true, output a number.
  5. Enlarge i.
  6. If i is less than 10,000, go to step 2.

    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.