Advertisement
Johnqc

Problema 1 PC2 unidad4

Jun 1st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. void TemperaturaPromedio (short *temperatura, short n){
  7. short sumatoria=0;
  8. for (short i=0; i<n; i++){
  9. sumatoria+=temperatura[i];
  10. }
  11. cout << "La temperatura Promedio es de: " << (sumatoria/n) << endl;
  12. }
  13.  
  14. void Mayor (short *temperatura, short n){
  15. short mayor=temperatura[0];
  16. for (short i=1; i<n; i++){
  17. if (mayor<temperatura[i])
  18. mayor=temperatura[i];
  19. }
  20. cout << "La mayor temperatura es: " << mayor << endl;
  21. }
  22.  
  23. void Menor (short *temperatura, short n){
  24. short menor=temperatura[0];
  25. for (short i=1;i<n; i++){
  26. if (menor >temperatura[i])
  27. menor=temperatura[i];
  28. }
  29. cout << "La menor temperatura es: " << menor << endl;
  30.  
  31. }
  32.  
  33. void Ordenamiento (short *temperatura, short n){
  34. short aux=0;
  35. for (short i=0;i<n;i++){
  36. for(short j=0; j<n-1;j++){
  37. if (temperatura[i]<temperatura[j]){
  38. aux=temperatura[j];
  39. temperatura[j]=temperatura[i];
  40. temperatura[i]=aux;
  41. }
  42. }
  43. }
  44. for (short i=0; i<n;i++){
  45. cout << temperatura[i] << " ";
  46. }
  47. }
  48.  
  49. int main (){
  50. short n;
  51. cout << "Introduce la cantidad de temperaturas: "; cin >> n;
  52. short* temperatura = new short [n];
  53.  
  54. for (short i=0; i<n; i++){
  55. cout << "Introduce la temperatura " << i+1 << ": "; cin >> temperatura[i];
  56. //while (temperatura[i]<8 || temperatura[i]>17);
  57. }
  58.  
  59. TemperaturaPromedio(temperatura, n);
  60. Mayor (temperatura, n);
  61. Menor (temperatura, n);
  62. Ordenamiento (temperatura, n);
  63.  
  64. getch();
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement