Advertisement
gtw7375

apostila while - question 3

Sep 16th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #innclude <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5.  
  6.  
  7.  main() {
  8.    
  9.     int cont=0, vet[9], i, j, soma=0, media, maior=0, menor=0, rdivi=0;
  10.    
  11.         for(i=0; i<9; i++) {
  12.        
  13.            
  14.             printf("Digite um numero");
  15.             scanf("%d", &vet[i]);
  16.            
  17.             if(vet[i] %2==0) {
  18.                
  19.                 rdivi +=vet[i];
  20.             }
  21.                
  22.             soma += vet[i];                            //soma dos n digitados
  23.             media = soma / 9;                         //media
  24.             cont++;                                  //contador
  25.         }
  26.        
  27.         for(j=0; j<9; j++) {
  28.            
  29.                 if(j==0) {
  30.                     maior=vet[j];
  31.                     menor=vet[j];
  32.                 }
  33.                
  34.                 else if(vet[j] > maior) {
  35.                    
  36.                     maior = vet[j];
  37.                     menor=menor;
  38.                 } else if
  39.                
  40.                     (vet[j] < menor) {
  41.                         menor = vet[j];
  42.                         maior=maior;
  43.                        
  44.                 } else {
  45.                     maior=maior;
  46.                     menor=menor;
  47.                 }
  48.         }
  49.        
  50.         printf("A soma e: %d \n \n", soma);
  51.    
  52.         printf("Foram digitados %d numeros \n \n", cont);
  53.    
  54.         printf("A media e: %d \n \n", media);
  55.        
  56.         printf("O maior numero digitado foi: %d \n \n", maior);
  57.  
  58.             printf("O menor numero digitado foi: %d \n \n", menor);
  59.        
  60.             printf("A soma dos pares e: %d \n \n", rdivi);
  61.     getch();
  62.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement