# abc_bca_cab_are_in_gp.c

Sep 21st, 2020 (edited)
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2.
3.     abc_bca_cab_are_in_gp.c
4.
8.
9.     'abc' is a 3-digit number such that
10.     'abc', 'bca' &'cab' are in G.P. Find all such numbers.
11.
12.     G.P. is geometric progression.
13.     https://en.wikipedia.org/wiki/Geometric_progression
14.
15.     x    y     z
16.
17.     x   r*x (r^2)*x
18.
19.     y/x = r and z/y = r
20.
21.     bca/abc = r and cab/bca = r
22.
23.     Condition is:
24.     bca/abc = cab/bca = r
25.
26.     Since 'abc', 'bca' and 'cab' are 3-digit numbers, a, b an c must not be 0.
27.
28.
29.     You can find all my C programs at Dragan Milicev's pastebin:
30.
31.     https://pastebin.com/u/dmilicev
32.
33. */
34.
35. #include <stdio.h>
36.
37. int main(void)
38. {
39.     int a, b, c, abc, bca, cab, solved=0, number_of_solutions=0;
40.
41.     printf("\n  abc  bca  cab \n");
42.
43.     for(a=1; a<10; a++)
44.         for(b=1; b<10; b++)
45.             for(c=1; c<10; c++)
46.             {
47.                 abc = a*100 + b*10 + c;
48.                 bca = b*100 + c*10 + a;
49.                 cab = c*100 + a*10 + b;
50.
51.                 if( (float)bca/abc == (float)cab/bca )
52.                 {
53.                     solved = 1;
54.                     number_of_solutions++;
55.                     printf("\n %4d %4d %4d , r = %d%d%d/%d%d%d = %.2f , r = %d%d%d/%d%d%d = %.2f \n",
56.                         abc, bca, cab, b,c,a, a,b,c, (float)bca/abc, c,a,b, b,c,a, (float)cab/bca );
57.                 }
58.             }
59.
60.     if( !solved )
61.         printf("\n There is no such digits. \n");
62.     else
63.         printf("\n There are %d such numbers. \n",number_of_solutions);
64.
65.
66.     return 0;
67.
68. } // main()
69.
RAW Paste Data Copied