fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int prime_local(int n, int m) {
  5. div_t d;
  6. return ((d = div(n, m)).rem == 0) ? 0 : (d.quot < m) ? 1 : prime_local(n, m + 1);
  7. }
  8.  
  9. int prime(int n) { return (n == 1) ? 0 : (n == 2) ? 1 : (prime_local(n, 2)); }
  10.  
  11. int main() {
  12. int n;
  13.  
  14. #if 1
  15. do { printf("n = \n"); scanf("%d", &n);
  16. } while (n <= 0);
  17. #else
  18. for (n = 2; n < 100; n++)
  19. #endif
  20. printf((prime(n) ? "%d prime number.\n" : "%d not prime\n"), n);
  21. return 0;
  22. }
  23. /* end */
  24.  
Success #stdin #stdout 0.02s 2728KB
stdin
Standard input is empty
stdout
n = 
134514393 not prime