Maximum, Minimum dan Jumlah

Posted: 1 Juli 2013 in Praktikum Alpro

Source C++ :

#include <cstdlib>
#include <iostream>

using namespace std;
class maxmin{
public:
maxmin();
int proses(int n, int i,int max, int min, int jumlah);
private:
int n,i,max,min,jumlah,x;
};
maxmin::maxmin(){
cout<<“mencari maximum, minimum dan total dari n bilangan “<<endl;
}
int maxmin::proses(int n, int i, int max, int min, int jumlah){
if (i>n){
cout<<“nilai maximum :”<<max<<endl;
cout<<“nilai minimum :”<<min<<endl;
cout<<“jumlah :”<<jumlah<<endl;
}
else{
cout<<“masukkan bilangan ke-“<<i<<” :”;
cin>>x;
jumlah+=x;
if(x<min){
min=x;
}
if(x>max){
max=x;
}
return proses(n,i+1,max,min,jumlah);
}

}

int main(int argc, char *argv[])
{
maxmin x;
int n;
cout<<“masukkan banyak data :”; cin>>n;
x.proses(n,1,0,1000,0);
system(“PAUSE”);
return EXIT_SUCCESS;
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s