Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. void histograma(int temp[])
  2. {
  3. int menor_temp, maior_temp, soma = 0, media;
  4.  
  5. for(int i = 0;i < 7;i++)
  6. {
  7. for(int j = 0;j < temp[i];j++)
  8. {
  9. printf("▪");
  10. }
  11. printf("\n");
  12. }
  13. menor_temp = temp[0];
  14. maior_temp = temp[0];
  15. for(int i = 0;i < 7;i++)
  16. {
  17. if(temp[i] < menor_temp) menor_temp = temp[i]; /* procura a menor temperatura */
  18. else if(temp[i] > maior_temp) maior_temp = temp[i]; /*procura a maior temperatura */
  19. soma += temp[i];
  20. }
  21. media = soma/7;
  22. printf("Informações:\n");
  23. printf("A menor temperatura é %d\n", menor_temp);
  24. printf("A maior temperatura é %d\n", maior_temp);
  25. printf("A media das temperaturas é %d\n", media);
  26.  
  27. }
  28.  
  29. int main(int argc, char **argv)
  30. {
  31. int temp[7];
  32.  
  33. printf("Histograma de temperaturas semanais\n");
  34. printf("Digite as temperaturas:\n");
  35.  
  36. for(int i = 0;i < 7;i++)
  37. {
  38. printf("Temperatura? ");
  39. scanf("%d", &temp[i]);
  40. }
  41.  
  42. histograma(temp);
  43.  
  44. return 0;
  45. }
  46.  
  47. O output desse código é esse:
  48.  
  49. Histograma de temperaturas semanais
  50. Digite as temperaturas:
  51. Temperatura? 24
  52. Temperatura? 36
  53. Temperatura? 12
  54. Temperatura? 8
  55. Temperatura? 15
  56. Temperatura? 5
  57. Temperatura? 3
  58. ▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪
  59. ▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪
  60. ▪▪▪▪▪▪▪▪▪▪▪▪
  61. ▪▪▪▪▪▪▪▪
  62. ▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪
  63. ▪▪▪▪▪
  64. ▪▪▪
  65. Informações:
  66. A menor temperatura é 3
  67. A maior temperatura é 36
  68. A media das temperaturas é 14
  69.  
  70. Tenho que fazer com que em vez de imprimir o histograma na horizontal, seja imprimido na vertical. Já tentei mudar a condição do for, adicionar mais um mas não deu certo...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement