Advertisement
hercioneto

[tds2023] Código em C para Função

Dec 6th, 2023
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. // Online C compiler to run C program online
  2. #include <stdio.h>
  3. void oi() {
  4.     char texto[] = "Sou uma function \n";
  5.     printf ("%s",texto);
  6. }
  7. int soma(int a, int b) {
  8.     int resultado;
  9.     resultado = a + b;
  10.     return resultado;
  11. }
  12. int diminuir(int a, int b) {
  13.     int resultado;
  14.     resultado = a - b;
  15.     return resultado;
  16. }
  17. int multiplicar(int a, int b) {
  18.     int resultado;
  19.     resultado = a * b;
  20.     return resultado;
  21. }
  22. int dividir(int a, int b) {
  23.     int resultado;
  24.     if (b==0) {
  25.         return 0;
  26.     } else {
  27.         resultado = a / b;
  28.         return resultado;
  29.     }
  30. }
  31.  
  32. int main() {
  33.     //oi();
  34.     int total = soma(5,7);
  35.     printf("%i \n",total);
  36.     int v1, v2;
  37.     printf("Digite valor: ");
  38.     scanf("%i",&v1);
  39.     printf("Digite valor: ");
  40.     scanf("%i",&v2);
  41.     total = soma(v1,v2);
  42.     printf("Somar %i \n",total);
  43.    
  44.     total = diminuir(v1,v2);
  45.     printf("Diminuir %i \n",total);
  46.    
  47.     total = multiplicar(v1,v2);
  48.     printf("Multiplicar %i \n",total);
  49.    
  50.     total = dividir(v1,v2);
  51.     printf("Divisao %i \n",total);
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement