Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int somavetor(int vetor[], int tam){
- if (tam == 0){
- return 0;
- }
- else {
- int s;
- s = somavetor (vetor, tam-1);
- if (vetor[tam-1] > 0){
- s += vetor[tam-1];
- return (s);
- }
- }
- }
- int main(){
- int tamanho = 0,i,somatorio;
- printf("Digite o tamanho do vetor:\n");
- scanf("%d",&tamanho);
- printf("Digite o vetor:\n");
- int vetor[tamanho];
- for (i=0; i<tamanho; i++){
- scanf("%d", &vetor[i]);
- }
- somatorio = somavetor(vetor,tamanho);
- printf("A soma é %d\n", somatorio);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement