dmilicev

three_digits_numbers_v2.c

Sep 4th, 2020 (edited)
183
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     three_digits_numbers_v2.c
  4.  
  5.     Task:
  6.     How many three digits numbers can be formed using the digits 1 to 9
  7.     such that digits in
  8.     Hundred's place is  greater than the digits in Ten's place and
  9.     the digits in Ten's place is greater than the digits in Unit's place ?
  10.  
  11.  
  12.     You can find all my C programs at Dragan Milicev's pastebin:
  13.  
  14.     https://pastebin.com/u/dmilicev
  15.  
  16. */
  17.  
  18. #include <stdio.h>
  19.  
  20. int main(void)
  21. {
  22.     int h, t, u, number_of_solutions=0, number_of_iterations=0;
  23.  
  24.     // from 321 to 987
  25.     for(h=3; h<10; h++)
  26.     {
  27.         printf("\n\n");
  28.  
  29.         for(t=2; t<9; t++)
  30.             for(u=1; u<8; u++)
  31.             {
  32.                 number_of_iterations++;
  33.                 if( h>t && t>u )
  34.                 {
  35.                     number_of_solutions++;
  36.                     printf(" %d%d%d", h, t, u );
  37.                 }
  38.             }
  39.     }
  40.  
  41.     if( number_of_solutions == 0 )
  42.         printf("\n There is no such numbers. \n");
  43.     else
  44.         printf("\n\n There are %d such numbers. \n", number_of_solutions );
  45.  
  46.     printf("\n Number of iterations %d. \n", number_of_iterations );
  47.  
  48.     return 0;
  49.  
  50. } // main()
  51.  
RAW Paste Data Copied