dmilicev

three_digits_numbers_v1.c

Sep 4th, 2020
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     three_digits_numbers_v1.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;
  23.  
  24.     for(h=1; h<10; h++)
  25.         for(t=1; t<10; t++)
  26.             for(u=1; u<10; u++)
  27.             {
  28.                 if( h>t && t>u )
  29.                 {
  30.                     number_of_solutions++;
  31.                     printf(" %d%d%d ", h, t, u );
  32.                 }
  33.             }
  34.  
  35.     if( number_of_solutions == 0 )
  36.         printf("\n There is no such numbers. \n");
  37.     else
  38.         printf("\n\n There are %d such numbers. \n", number_of_solutions );
  39.  
  40.     return 0;
  41.  
  42. } // main()
  43.  
RAW Paste Data Copied