Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3.  
  4. int produto(int n1,int n2);
  5. int quociente(int n1, int n2);
  6. int resto(int n1, int n2);
  7.  
  8. /*definicao da funcao produto*/
  9. int produto(int n1, int n2 )
  10. {
  11.      float p=0;
  12.      int i;
  13.      printf("Entre com os valores");
  14.      scanf("%d%d", &n1,&n2);
  15.    
  16.     for(i=0;i<n1;i++)
  17.     {
  18.     p +=n2;
  19.     }
  20.     return p;
  21. }
  22.  
  23. /*definicao da funcao quociente*/
  24. int quociente(int n1, int n2 )
  25. {
  26.      int q;
  27.      int r;
  28.      
  29.      printf("Entre com os valores");
  30.      scanf("%d%d", &n1,&n2);
  31.    
  32.     while(n1>=n2)
  33.     {    
  34.     n1-=n2;
  35.        
  36.        if (n1>=0)
  37.        {
  38.        q++;
  39.        r = n1;
  40.        }
  41.    }
  42.        //q = n1 / n2;
  43.     return q;
  44. }
  45.  
  46. /*definicao da funcao resto*/
  47. int resto(int n1, int n2 )
  48. {
  49.      int q;
  50.      int r;
  51.      
  52.      printf("Entre com os valores");
  53.      scanf("%d%d", &n1,&n2);
  54.    
  55.      while(n1>=n2)
  56.      {    
  57.      n1-=n2;
  58.        
  59.        if (n1>=0)
  60.        {
  61.        q++;
  62.        r = n1;
  63.        }
  64.    }
  65.        return r;
  66. }
  67.  
  68. int main ( )
  69. {
  70.     int n1,n2;
  71.     int op;
  72.    
  73.     printf("******Calculadora***********");
  74.     printf("Escola uma das opcoes abaixo:\n");
  75.     printf("1 - Produto 2 - Quociente ou 3 - Resto");
  76.     scanf("%d",&op);
  77.        
  78.     switch (op)
  79.     {
  80.        case 1: printf(" %0.d",produto(n1,n2));break;
  81.        case 2: printf(" %0.d",quociente(n1,n2));break;
  82.        case 3: printf(" %0.d",resto(n1,n2));break;
  83.     }
  84.  
  85.    printf("\n\n\n");
  86.    getch();
  87.    return 0;
  88.      
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement