Hai kawan-kawan........
inilah sebuah program kecil
#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { cout<<"\t\tProgram menampilkan nilai Max-Min\n\n"; int n, max, min;//deklarasi variabel awal //input cout<<"Masukkan banyak data : "; cin>>n; cout<<endl; int data[n];//deklarasi array for(int i=0;i<n;i++){ cout<<"Masukkan data ke-"<<i+1<<" : "; cin>>data[i]; } //proses cari max-min max=min=data[0]; for(int i=1;i<n;i++){ if(data[i]>max){ max=data[i]; } else if(data[i]<min){ min=data[i]; } } //output cout<<"\nBanyak data : "<<n; cout<<"\nMax : "<<max; cout<<"\nMin : "<<min; cout<<endl<<endl; system("PAUSE"); return EXIT_SUCCESS; }
0 comments:
Post a Comment