Kamis, 23 Maret 2017
Pratikum MATDIS #2
Pada Pratikum Matdis (Matematika Diskrit) yang ke 2 Saya Akan Membuat Program Mencari KPK Dan FPB.
#include <cstdlib>
#include <iostream>
using namespace std;
int main(){
int i,j,a,b,r,kpk;
int p;
kpk=0;
cout<<"1. Menentukan KPK"<<endl;
cout<<"2. Menentukan FPB"<<endl;
cout<<"3. EXIT"<<endl;
cout<<"Masukkan pilihan anda : ";
cin>>p;
switch (p){
case 1:
cout<<"\nMencari KPK"<<endl;
cout<<"Masukkan Bilangan Pertama : ";
cin>>a;
cout<<"Masukkan Bilangan Kedua : ";
cin>>b;
cout<<endl;
cout<<a<<" = ";
for(i=a;i<=50;i++){
if(i%a==0){
cout<<i<<", ";
}
}
cout<<endl;
cout<<b<<" = ";
for(j=b;j<=50;j++){
if(j%b==0){
cout<<j<<", ";
}
}
for(i=1;i<=b;i++){
kpk=kpk+a;
if(kpk % b==0){
cout<<"\n\nKPK : "<<kpk<<endl;
break;
case 2:
cout<<"\nMencari FPB"<<endl;
cout << "Masukkan Bilangan Pertama : ";
cin >>a;
cout << "Masukan Bilangan Kedua : " ;
cin >>b;
r = a%b;
do{
cout << a << " : " << b << " = " << a/b << " sisa " << r << endl;
a = b;
b = r;
r = a%b;
}
while (r!=0);
cout <<"\n" <<a << " : " << b << " = " << a/b << " sisa " << r << endl;
cout << "\nmaka FPB dari kedua nilai tersebut adalah: " << b << endl;
break;
case 3:
cout<<"EXIT Now !!!"<<endl;
break;
default:
cout<<"Error !!!"<<endl;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar