Advertisement
jacknpoe

Contando idades

Nov 15th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. #define QUANTIDADE 6
  5.  
  6. int main(){
  7.     int idade, idades[] = { 0, 0, 0, 0, 0 };
  8.     char *desc[] = { "criancas", "jovens", "adultos", "idosos", "muito idosos" };
  9.    
  10.     for( int i = 0; i < QUANTIDADE; i ++ ) {
  11.         printf( "Entre com a idade: ");
  12.         scanf( "%d", &idade);
  13.  
  14.         idade = ( idade - 1) / 15;
  15.         idades[ ( idade > 4 ? 4 : idade) ] ++;
  16.     }
  17.  
  18.     printf( "\n" );
  19.  
  20.     for( int i = 0; i < 5; i ++ )
  21.         printf( "A quantidade de %s e: %d e corresponde a %.2f porcento da pesquisa\n", desc[i], idades[i], (float) idades[i] * 100 / QUANTIDADE );
  22.  
  23.     system( "PAUSE");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement