# Answer to Question #29503 in C++ for Chake

Question #29503

Write that selects and displays the maximum value of five numbers to be entered when the program is executed.

Expert's answer

# include<iostream.h>

# include<conio.h>

void main(){

float a[5], min, max;

int i;

for (i=0;i<5;i++){

& cout<<"Enter a number "<<i+1<<": ";

& cin>>a[i];

}

min = a[0];

max = a[0];

for (i=0;i<5;i++){

& if (a[i]>max) max = a[i];

& if (a[i]<min) min = a[i];

}

cout<<"Minimum is "<<min<<"\n"<<" Maximum is "<<max;

getch();

}

# include<conio.h>

void main(){

float a[5], min, max;

int i;

for (i=0;i<5;i++){

& cout<<"Enter a number "<<i+1<<": ";

& cin>>a[i];

}

min = a[0];

max = a[0];

for (i=0;i<5;i++){

& if (a[i]>max) max = a[i];

& if (a[i]<min) min = a[i];

}

cout<<"Minimum is "<<min<<"\n"<<" Maximum is "<<max;

getch();

}

## Comments

## Leave a comment