Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- void TemperaturaPromedio (short *temperatura, short n){
- short sumatoria=0;
- for (short i=0; i<n; i++){
- sumatoria+=temperatura[i];
- }
- cout << "La temperatura Promedio es de: " << (sumatoria/n) << endl;
- }
- void Mayor (short *temperatura, short n){
- short mayor=temperatura[0];
- for (short i=1; i<n; i++){
- if (mayor<temperatura[i])
- mayor=temperatura[i];
- }
- cout << "La mayor temperatura es: " << mayor << endl;
- }
- void Menor (short *temperatura, short n){
- short menor=temperatura[0];
- for (short i=1;i<n; i++){
- if (menor >temperatura[i])
- menor=temperatura[i];
- }
- cout << "La menor temperatura es: " << menor << endl;
- }
- void Ordenamiento (short *temperatura, short n){
- short aux=0;
- for (short i=0;i<n;i++){
- for(short j=0; j<n-1;j++){
- if (temperatura[i]<temperatura[j]){
- aux=temperatura[j];
- temperatura[j]=temperatura[i];
- temperatura[i]=aux;
- }
- }
- }
- for (short i=0; i<n;i++){
- cout << temperatura[i] << " ";
- }
- }
- int main (){
- short n;
- cout << "Introduce la cantidad de temperaturas: "; cin >> n;
- short* temperatura = new short [n];
- for (short i=0; i<n; i++){
- cout << "Introduce la temperatura " << i+1 << ": "; cin >> temperatura[i];
- //while (temperatura[i]<8 || temperatura[i]>17);
- }
- TemperaturaPromedio(temperatura, n);
- Mayor (temperatura, n);
- Menor (temperatura, n);
- Ordenamiento (temperatura, n);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement