The Aristocats - Marie

animasi

Tugas Kelompok 3.2 (EBook) Pertemuan 3

Senin, 17 Maret 2014



Mencari nilai KPK 3.2
  • ANALISIS 3.2 

1.       INPUT : x,y ( masukan nilai KPK )
2.       PROSES : x>y
                         kecil <-  y
                         kecil <-  x
3.       INISIALISASI : i <- 1
4.       PERULANGAN
5.       PROSES : a <- x % i  
                         b <- y % i
6.       PROSES : a=0 && b=0 MAKA c <- 1
7.       PROSES : i>=kecil
                         i <- i+1
                         kpk <- (x*y)/c
8.       OUTPUT : x,y,kpk (hasil kpk)

  • Algoritma
1.       Deklarasi
       x, y : integer (input)
       x, y, kpk : hasil kpk (output)

2.       Deskripsi
       READ (x,y)
       a <- m%i 
       b <- n%i 
       kondisi a=0 && b=0
       c <-1
       kondisi i>=kecil
       i <- i+1
       kpk <- (x*y)/c

write (x, y, kpk)

  • Flowchart : 

RUN :
  • Bahasa C++ :
class Kpk {
      public :
             void masukkan ();
             void proses();
      private:
             int i,x,y,a,b,c,kpk,kecil;
};

void Kpk :: masukkan(){
        cout<< "masukkan x : "; cin >> x;
        cout<< "masukkan y : "; cin >> y;
        }

void Kpk :: proses(){
     if (x>y){
      kecil =y;
   }
   else{
      kecil =x;
   }
   i =1;
   while (1){
      a =x % i;
      b =y % i;
      if (a==0 && b==0){
         c =i;
      }
      else{
      }
      if (i>=kecil) break;
      i =i+1;
      kpk =(x*y)/c;
   }
   cout<< "x= "<<x<<endl;
   cout<< "y= "<<y<<endl;
   cout << "KPKnya : " << kpk << endl;
}
int main(int argc, char *argv[])
{
    Kpk cetak;
    cetak.masukkan();
    cetak.proses();


RUN :




0 komentar:

Posting Komentar