Advertisement
B1KMusic

Composite Number Program #2

Jul 6th, 2016
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void
  5. factor(int n)
  6. {/*{{{*/
  7.     int i,
  8.         total = 0;
  9.  
  10.     printf("%i: ", n);
  11.  
  12.     for(i = 1; i <= n; i++){
  13.         if(n % i == 0){
  14.             printf("%i ", i);
  15.             fflush(stdout);
  16.             total++;
  17.         }
  18.     }
  19.  
  20.     printf("\ntotal: %i\n", total);
  21. }/*}}}*/
  22.  
  23. void
  24. usage(char *pname)
  25. {/*{{{*/
  26.     printf("Usage: %s [n1] [n2] [...]\n", pname);
  27. }/*}}}*/
  28.  
  29. void
  30. parseArgs(char **args)
  31. {/*{{{*/
  32.     while(*args){
  33.         factor(atoi(*args));
  34.         args++;
  35.     }
  36. }/*}}}*/
  37.  
  38. int
  39. main(int argc, char **argv)
  40. {/*{{{*/
  41.     if(argv[1]){
  42.         parseArgs(argv + 1);
  43.     } else {
  44.         usage(*argv);
  45.     }
  46.  
  47.     return 0;
  48. }/*}}}*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement