Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- abc_bca_cab_are_in_gp.c
- Task from Subir Singha:
- https://www.facebook.com/groups/1941400139499670/user/100002028618086/
- https://www.facebook.com/groups/1941400139499670/permalink/2392741967698816/
- 'abc' is a 3-digit number such that
- 'abc', 'bca' &'cab' are in G.P. Find all such numbers.
- G.P. is geometric progression.
- https://en.wikipedia.org/wiki/Geometric_progression
- x y z
- x r*x (r^2)*x
- y/x = r and z/y = r
- bca/abc = r and cab/bca = r
- Condition is:
- bca/abc = cab/bca = r
- Since 'abc', 'bca' and 'cab' are 3-digit numbers, a, b an c must not be 0.
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int main(void)
- {
- int a, b, c, abc, bca, cab, solved=0, number_of_solutions=0;
- printf("\n abc bca cab \n");
- for(a=1; a<10; a++)
- for(b=1; b<10; b++)
- for(c=1; c<10; c++)
- {
- abc = a*100 + b*10 + c;
- bca = b*100 + c*10 + a;
- cab = c*100 + a*10 + b;
- if( (float)bca/abc == (float)cab/bca )
- {
- solved = 1;
- number_of_solutions++;
- printf("\n %4d %4d %4d , r = %d%d%d/%d%d%d = %.2f , r = %d%d%d/%d%d%d = %.2f \n",
- abc, bca, cab, b,c,a, a,b,c, (float)bca/abc, c,a,b, b,c,a, (float)cab/bca );
- }
- }
- if( !solved )
- printf("\n There is no such digits. \n");
- else
- printf("\n There are %d such numbers. \n",number_of_solutions);
- return 0;
- } // main()
Add Comment
Please, Sign In to add comment