mencari max dan min




Program
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
int  angka,n, max=-1, min=101;
cout << "Masukkan jumlah bilangan yang diinputkan: ";
            cin>>n;
                        for ( int i =1;i<=n;i++){
                                    cout << "Masukkan Angka         : ";
                                    cin>>angka;
                                    if ( min > angka ) {
                                                min = angka;
                                    }
                                    else if ( max < angka) {
                                                max = angka;
                                    }      
                         }
            cout << endl;
            cout << "Nilai maximum           : " <<  max<< endl;
            cout << "Nilai minimum           : " <<  min<< endl;

system("pause");
return 0;
}

Running

0 komentar:

Posting Komentar

Copyright 2009 my dear. All rights reserved.
Bread Machine Reviews | watch free movies online by Blogger Templates