CodingforEveryDay #2 : Algoritma Menentukan Max-Min List Number Tanpa Array

Code dalam c++

#include <iostream>
#include <conio.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(void) {
int i, n, val,min,max=0;
cout<<"how many number you want enter ? ";
cin>>n;
cout<<"enter your number : "<<endl;
cin>>val;
min=val;
if(val>=max){
max=val;

}
for(i=1;i<n;i++){
cin>>val;
if(val>max){
max=val;
}
if(val<min){
min=val;}
}
cout<<" Maximum number is : "<<max<<endl;
cout<<" Minimum number is : "<<min<<endl;
getch ();
}

input : 
how many number you want enter : 5
enter your number : 
12
32
44
65
76

output :
Maximum number is : 76
Minimum number is : 12

Penjelasan

untuk lebih jelas