Advertisement
paulogp

Divisão e resto (v. 1.0.3)

Jul 13th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. // Apple Xcode
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7.  
  8. // funcao
  9. void minha_divisao(int the_quocient, int the_div, int *the_result_div, int *the_result_rest)
  10. {
  11.     *the_result_div = the_quocient / the_div;
  12.     *the_result_rest = the_quocient % the_div;
  13. }
  14.  
  15.  
  16. // main
  17. int main (int argc, const char * argv[])
  18. {
  19.     if (argc == 3)
  20.     {
  21.         char *the_temp; // guarda o que nao consegue converter
  22.  
  23.         // strtol obtido a partir do terminal ./nome_programa var1 var2
  24.         int the_quocient = strtol(argv[1], &the_temp, 0); // strtol(argv[1], NULL, 0);
  25.         int the_div = strtol(argv[2], &the_temp, 0); // strtol(argv[2], NULL, 0);
  26.  
  27.         int the_result_div;
  28.         int the_result_rest;
  29.  
  30.         if (the_div != 0)
  31.         {
  32.             minha_divisao(the_quocient, the_div, &the_result_div, &the_result_rest);
  33.             printf("div = %i\n", the_result_div);
  34.             printf("resto = %i\n", the_result_rest);
  35.         }
  36.     } else {
  37.         printf("inseridos %i, 2 valores necessarios!\n", argc-1);
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement