Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int tc,i,total=0,num,c=0,r=0,s=0;
  5. char name;
  6. double per_c,per_r,per_s;
  7. scanf("%d",&tc);
  8.  
  9. for(i=0;i<tc;i++){
  10. scanf("%d %c",&num,&name);
  11.  
  12. total=total+num;
  13.  
  14. if(name=='C'){
  15. c=c+num;
  16. }
  17. else if(name=='R'){
  18. r=r+num;
  19. }
  20. else if(name=='S'){
  21. s=s+num;
  22. }
  23. }
  24. per_c= ((c/double(total))*100);
  25. per_r=((r/double(total))*100);
  26. per_s=((s/double(total))*100);
  27.  
  28. printf("Total: %d cobaias\n",total);
  29. printf("Total de coelhos: %d\n",c);
  30. printf("Total de ratos: %d\n",r);
  31. printf("Total de sapos: %d\n",s);
  32. printf("Percentual de coelhos: %0.2lf %%\n",per_c);
  33. printf("Percentual de ratos: %0.2lf %%\n",per_r);
  34. printf("Percentual de sapos: %0.2lf %%\n",per_s);
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement