dmilicev

three_digits_numbers_2_v1.c

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