Advertisement
luizaspan

Aula funções IV

Jun 23rd, 2015
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. // #include "q.c"
  5.  
  6. // #include <stdio.h>
  7.  
  8. int divisor(int n)
  9. {
  10.     int i,x=0,a;
  11.  
  12.     for (i=1;i<=n;i++)
  13.     {
  14.         a=n%i;
  15.  
  16.         if (a==0) // i é divisor de n
  17.             x+=i;
  18.     }
  19.  
  20.     return x;
  21. }
  22.  
  23. int main(int argc, char *argv[])
  24. {
  25.         if (argc != 2) // quero pedir só um argumento
  26.         {
  27.                 printf("Uso correto: %s n \n",argv[0]);
  28.                 exit(1);
  29.         }
  30.  
  31.         int n = (int) atoi(argv[1]);
  32.         // int N = (int) atoi(argv[2]);
  33.         // float dt = (float) atof(argv[3]);
  34.  
  35.         // strcpy(filename,argv[4]);
  36.  
  37.         int f;
  38.  
  39.         f=divisor(n);
  40.  
  41.         printf("%d \n",f);
  42.  
  43.         return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement