Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- digits_for_the_sum_of_three_numbers.c
- Find the values of x, y and z
- so that they can fulfill the given condition.
- Each digit x, y and z may have value between 0 to 9.
- xyx
- xyz
- +xzz
- -----
- 1416
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- https://www.facebook.com/dmilicev
- */
- #include <stdio.h>
- int main(void)
- {
- int x, y, z, solved = 0, sum = 1416;
- int num1, num2, num3;
- for(x=0; x<10; x++)
- for(y=0; y<10; y++)
- for(z=0; z<10; z++)
- {
- num1 = x*100 + y*10 + x;
- num2 = x*100 + y*10 + z;
- num3 = x*100 + z*10 + z;
- if( num1 + num2 + num3 == sum )
- {
- solved = 1;
- printf("\n x = %d , y = %d , z = %d \n", x,y,z);
- printf("\n %5d ", num1);
- printf("\n %5d ", num2);
- printf("\n+%5d ", num3);
- printf("\n---------");
- printf("\n %5d \n", sum);
- }
- }
- if( !solved )
- printf("\n There is no such digits. \n");
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement