Advertisement
lButcherl

Vetor 06

Oct 29th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. /*6. Crie um algoritmo que leia o vetor com 10 números e some apenas os elementos positivos que estão nas
  2. posições pares. */
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #define tam 10
  7.  
  8. main(){
  9.        int i;
  10.        float vet[tam],soma=0;
  11.        for (i=0; i < tam; i++){
  12.            printf("Informe um numero: ");
  13.            scanf("%f",&vet[i]);
  14.            if (vet[i] >= 0 && i % 2 == 0){
  15.                       soma = soma + vet[i];
  16.                       }
  17.            }
  18.            printf("A soma deu %.0f\n",soma);
  19.                       system("pause");
  20.                       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement