Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- three_digits_numbers_v2.c
- Task:
- How many three digits numbers can be formed using the digits 1 to 9
- such that digits in
- Hundred's place is greater than the digits in Ten's place and
- the digits in Ten's place is greater than the digits in Unit's place ?
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int main(void)
- {
- int h, t, u, number_of_solutions=0, number_of_iterations=0;
- // from 321 to 987
- for(h=3; h<10; h++)
- {
- printf("\n\n");
- for(t=2; t<9; t++)
- for(u=1; u<8; u++)
- {
- number_of_iterations++;
- if( h>t && t>u )
- {
- number_of_solutions++;
- printf(" %d%d%d", h, t, u );
- }
- }
- }
- if( number_of_solutions == 0 )
- printf("\n There is no such numbers. \n");
- else
- printf("\n\n There are %d such numbers. \n", number_of_solutions );
- printf("\n Number of iterations %d. \n", number_of_iterations );
- return 0;
- } // main()
Add Comment
Please, Sign In to add comment