Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int somavetor(int vetor[], int tam){
  5. if (tam == 0){
  6. return 0;
  7. }
  8.  
  9. else {
  10. int s;
  11. s = somavetor (vetor, tam-1);
  12.  
  13. if (vetor[tam-1] > 0){
  14. s += vetor[tam-1];
  15. return (s);
  16. }
  17. }
  18. }
  19.  
  20.  
  21. int main(){
  22. int tamanho = 0,i,somatorio;
  23. printf("Digite o tamanho do vetor:\n");
  24. scanf("%d",&tamanho);
  25. printf("Digite o vetor:\n");
  26.  
  27. int vetor[tamanho];
  28. for (i=0; i<tamanho; i++){
  29. scanf("%d", &vetor[i]);
  30. }
  31. somatorio = somavetor(vetor,tamanho);
  32. printf("A soma é %d\n", somatorio);
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement