# digits_for_the_sum_of_three_numbers.c

Jan 28th, 2020
237
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2.
3.     digits_for_the_sum_of_three_numbers.c
4.
5.     Find the values of x, y and z
6.     so that they can fulfill the given condition.
7.
8.     Each digit x, y and z may have value between 0 to 9.
9.
10.     xyx
11.     xyz
12.    +xzz
13.    -----
14.    1416
15.
16.
17.     You can find all my C programs at Dragan Milicev's pastebin:
18.
19.     https://pastebin.com/u/dmilicev
20.
22.
23. */
24.
25. #include <stdio.h>
26.
27. int main(void)
28. {
29.     int x, y, z, solved = 0, sum = 1416;
30.     int num1, num2, num3;
31.
32.     for(x=0; x<10; x++)
33.         for(y=0; y<10; y++)
34.             for(z=0; z<10; z++)
35.             {
36.                 num1 = x*100 + y*10 + x;
37.                 num2 = x*100 + y*10 + z;
38.                 num3 = x*100 + z*10 + z;
39.
40.                 if( num1 + num2 + num3 == sum )
41.                 {
42.                     solved = 1;
43.                     printf("\n x = %d , y = %d , z = %d \n", x,y,z);
44.                     printf("\n %5d ", num1);
45.                     printf("\n %5d ", num2);
46.                     printf("\n+%5d ", num3);
47.                     printf("\n---------");
48.                     printf("\n %5d \n", sum);
49.                 }
50.             }
51.
52.     if( !solved )
53.         printf("\n There is no such digits. \n");
54.
55.     return 0;
56.
57. } // main()