Algoritma :
Deklarasi
a,b : integer
Deskripsi
if ( a > b ) && ( a > c )
then
write(a)
else if (b > a) && (b > c)
then
write(b)
else
then
write(c)
endif
Berikut programnya :
#include <iostream.h>
#include <conio.h>
class terbesar{
friend istream& operator >> (istream&, terbesar&);
friend ostream& operator << (ostream&, const terbesar&);
public:
terbesar();
void bandingkan(){
if ((a > b) && (a > c))
cout<< " Bilangan terbesar : "<<a;
else if ((b > a) && (b > c))
cout<< " Bilangan terbesar : "<<b;
else
cout<< " Bilangan terbesar : "<<c<<endl;
};
private:
int a,b,c;
};
terbesar::terbesar(){
cout << "menentukan bilangan terbesar dari yang diinputkan\n" << endl;
}
istream& operator >>(istream& cin, terbesar& masukan){
cout<<"masukan bilangan pertama : ";
cin>>masukan.a;
cout<<"masukan bilangan kedua : ";
cin>>masukan.b;
cout<<"masukan bilangan ketiga : ";
cin>>masukan.c;
cout<<endl;
return cin;
}
ostream& operator << (ostream& out, const terbesar& keluaran){
out<< " terima kasih "<<endl;
return out;
}
void main(){
terbesar bilangan;
cin>>bilangan;
bilangan.bandingkan();
cout<<bilangan;
getch();
}
Explanation:
The program above is the program used to search for the greatest number of 3 numbers are entered. This program uses the selection or conditional if ... else. Which process is if ((a> b) & & (a> c)) and will display a floating largest is a, then if ((b> a) & & (b> c)) will display the number of the largest is b but if not satisfy both these conditions it will display the greatest number is c.
The program above is the program used to search for the greatest number of 3 numbers are entered. This program uses the selection or conditional if ... else. Which process is if ((a> b) & & (a> c)) and will display a floating largest is a, then if ((b> a) & & (b> c)) will display the number of the largest is b but if not satisfy both these conditions it will display the greatest number is c.
1 komentar:
yang aku buat tadi barusan lebih simpel :)
Posting Komentar