Advertisement
dmilicev

numbers_divisible_by_all_digits_1-9.c

Dec 11th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. /*
  2.  
  3.     numbers_divisible_by_all_digits_1-9.c
  4.  
  5.  
  6.     Find all positive integers divisible by all digits 1,2,3,4,5,6,7,8,9.
  7.  
  8.  
  9.  
  10.  
  11.     You can find all my C programs at Dragan Milicev's pastebin:
  12.  
  13.     https://pastebin.com/u/dmilicev
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <limits.h>     // for USHRT_MAX = 65535
  19.  
  20.  
  21. int main(void)
  22. {
  23.     int i, counter=0;
  24.  
  25.     for ( i=1; i<USHRT_MAX; i++)
  26.     {
  27.         if ( (i%1 + i%2 + i%3 + i%4 + i%5 + i%6 + i%7 + i%8 + i%9) == 0 )
  28.         {
  29.             counter++;
  30.             printf("\n %3d. \t %5d \n", counter, i );
  31.         }
  32.     }
  33.  
  34.     printf("\n\n There are %d such numbers. \n\n", counter );
  35.  
  36.     return 0;
  37.  
  38. } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement