Advertisement
Joao_Joao

Questão 252 Lista de Exercícios IFPB

Apr 27th, 2022 (edited)
996
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. #define max(a, b) (a > b ? a : b)
  4. #define min(a, b) (a < b ? a : b)
  5.  
  6. int sum(int m, int n) {
  7.   int maior = max(m, n), menor = min(m, n);
  8.   if(maior == menor) return menor;
  9.   return maior + sum(maior-1, menor);
  10. }
  11.  
  12. int main() {
  13.   printf("A soma de todos os numeros do intervalo [M, N] eh: %d\n", sum(5, 1));
  14.  
  15.   return 0;
  16. }
  17.  
Advertisement
RAW Paste Data Copied
Advertisement