Program Fpb
#include<iostream.h>
#include<conio.h>
class fpb{
friend istream& operator>>(istream&, fpb&);
friend ostream& operator<<(ostream&, fpb&);
public:
int hitung(int n, int m);
private:
int m;
int n;
int r;
};
int fpb::hitung(int n, int m)
{r=m%n;
while(r!=0)
{ m=r;
n=r;
r=m%n;}
};
istream& operator>>(istream& cin, fpb& masukkan){
cout<<"********************"<<endl;
cout<<"menghitung nilai fpb"<<endl;
cout<<"*******************"<<endl;
cout<<"masukkan nilai pertama: ";
cin>>masukkan.n;
cout<<"masukkan nilai kedua: ";
cin>>masukkan.m;
return cin;}
ostream& operator<<(ostream& cout, fpb& keluaran){
cout<<"fpb nya adalah: ";
cout<<keluaran.n;
return cout;
}
int main(){
fpb x;
cin>>x;
cout<<x;
getch();
};
0 komentar:
Posting Komentar