Advertisement
noor017

Experiment

Jun 26th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int n, amount, total=0, coelho=0, rato=0, sapo=0;
  6.     double per_coelho, per_rato, per_sapo;
  7.     char type;
  8.  
  9.     scanf("%d", &n);
  10.     while(n--)
  11.     {
  12.         scanf("%d %c", &amount, &type);
  13.  
  14.         total=total+amount;
  15.  
  16.         if(type == 'C')
  17.         {
  18.             coelho=coelho+amount;
  19.         }
  20.  
  21.         else if(type == 'R')
  22.         {
  23.             rato=rato+amount;
  24.         }
  25.  
  26.         else if(type == 'S')
  27.         {
  28.             sapo=sapo+amount;
  29.         }
  30.  
  31.     }
  32.  
  33.     printf("Total: %d cobaias\n", total);
  34.     printf("Total de coelhos: %d\n", coelho);
  35.     printf("Total de ratos: %d\n", rato);
  36.     printf("Total de sapos: %d\n", sapo);
  37.  
  38.  
  39.     per_coelho=(coelho*100)/total;
  40.     per_rato=(rato*100)/total;
  41.     per_sapo=(sapo*100)/total;
  42.  
  43.     printf("Percentual de coelhos: %.2lf %%\n", per_coelho);
  44.     printf("Percentual de ratos: %.2lf %%\n", per_rato);
  45.     printf("Percentual de sapos: %.2lf %%\n", per_sapo);
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement