# ab_x_cd_equal_to_ba_x_dc_v1.c

May 14th, 2020
156
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2.
3.     ab_x_cd_equal_to_ba_x_dc_v1.c
4.
5.
6.     Find the two-digit numbers that apply to:
7.
8.     ab * cd = ba = dc
9.
10.
11.     You can find all my C programs at Dragan Milicev's pastebin:
12.
13.     https://pastebin.com/u/dmilicev
14.
15. */
16.
17. #include <stdio.h>
18.
19. int main(void)
20. {
21.     int a,b,c,d, counter=0;
22.
23.     for(a=0; a<=9; a++)
24.       for(b=0; b<=9; b++)
25.         for(c=0; c<=9; c++)
26.           for(d=0; d<=9; d++)
27.           {
28.             if( (a*10+b)*(c*10+d) == (b*10+a)*(d*10+c) &&
29.                 (a*10+b) > 9 &&
30.                 (b*10+a) > 9 &&
31.                 (c*10+d) > 9 &&
32.                 (d*10+c) > 9    )
33.             {
34.                 printf("\n %2d * %2d = %2d * %2d = %4d \n",
35.                   a*10+b, c*10+d, b*10+a, d*10+c, (a*10+b)*(c*10+d) );
36.                 counter++;
37.             }
38.           }
39.
40.           printf("\n There are %d pairs of such numbers. \n", counter );
41.
42.     return 0;
43.
44. } // main()
RAW Paste Data Copied