IJUL'S BLOG

Contoh Fungsi ,kpk,nonprima

catatn kuliahq:
 ni source code nya,agak ribet dikit sih bro:

#include<iostream.h>
#include<conio.h>

void KPK();
void nonprima();
void diskon();
void kelipatan();
float pot,tobel,poin,reward,M;
int x,y,i,h;
int batas, cek,m;

void main()
{
int kode;
 char pilihan;
 cobalagi:
 cout<< "\tMENU UTAMA\n\n";
 cout<<"1. Mencari NONPRIMA\n2. Menentukan Kelipatan x dan y\n";
 cout<<"3. Menentukan KPK \n4. Menentukan Potongan Harga\n\n";
 cout<<"Pilih menu (1..4): ";
 cin >>kode;
 switch(kode)
 {
 case 1:
 clrscr();
 cout<<"PROGRAM UNTUK MENENTUKAN DERET BILANGAN PRIMA"<<endl<<endl;
 cout<<"Batas dari Deret Bilangan non Prima y: ";
 cin>>m;
 cout<<endl;
 cout<<"Deret Bilangan non Prima sampai "<<m<<" adalah: "<<endl<<endl;
 nonprima();
 break;
 case 2:
 clrscr();
 cout<<"Masukkan nilai x : ";
 cin>>x;
 cout<<"Masukkan nilai y : ";
 cin>>y;
 kelipatan();
 break;
 case 3:
 clrscr();
 KPK();
 break;
 case 4:
 clrscr();
 cout<<"Masukan harga pembelian = ";
 cin>>tobel;
 diskon();
 break;
 default:
 clrscr();
 cout<<"Kode Salah";
 break;
 }
 cout<<"\n\nMau Ulangi Lagi...(Y/T)? : ";
  cin>>pilihan;
  if(pilihan == 'y' || pilihan == 'Y')
  {
    clrscr();
    goto cobalagi;
  }
 }


void diskon()
{

    if(tobel>1000000)
    {
        pot = tobel*0.30;
        M=tobel-(tobel*0.30);
        poin=30;
        reward=75000;
    }
    else if ((tobel==1000000)||(tobel>500000))
        {
        pot=tobel*0.20;
        M= tobel-(tobel*0.20);
        poin=20;
        reward=750000;
        }
        else if ((tobel==500000)||(tobel>300000))
        {
        pot=tobel*0.10;
        M=tobel-(tobel*0.10);
        poin=10;
        reward=50000;
        }
        else if ((tobel<=300000)||(tobel>=0))
        {
        pot=0;
        M=tobel;
        poin=0;
        reward=0;
        }

     cout<<"potongan harga = "<<"Rp. "<<pot<<endl;
     cout<<"Harga yang harus dibayar = "<<"Rp. "<<M<<endl;
     cout<<"poin = "<<poin<<endl;
     cout<<"Hadiah Voucher Belanja = "<<"Rp. "<<reward<<endl;
}



void kelipatan()
{


          h=0;
        for(i=1;i<=10;i++)
          {
        h=h+x;
          cout<<h<<", ";
          }
          cout<<endl;
        h=0;
          for(i=1;i<=10;i++)
        {
          h=h+y;
          cout<<h<<", ";
          }
          }

void KPK()
{
int a,b,nilai;

 cout<<"Masukkan Nilai Bil A : "; cin>>a;
 cout<<"Masukkan Nilai Bil B : "; cin>>b;
nilai=0;
 for( x=1;x<=b;x++)
 {
  nilai=nilai+a;

             if(nilai % b==0)
        {
         cout<<"KPK Antara "<<a<<" dan "<<b<<" Adalah "<<nilai;
        }
 }
}

void nonprima()
{



for (x =1; x<m; x++)
{
cek = 0;
if(x<2)
{
cout<<"1, ";
 }
for (i = 2; i < x; i++)
{
if (x % i == 0)
{
cek = 1;
}
}
if (cek != 0)
{
cout<<x<<", ";
}
}
{
cout<<endl<<endl<<endl;
}
getch();
}

0 komentar:

Posting Komentar

Powered By Blogger
Diberdayakan oleh Blogger.

Entri Populer

PENGUNJUNG

Buku Tamu

About Me

Foto Saya
Ijal Ferdi
there is no something special about me,,, but this blog is so special for me......
View my complete profile

Total Tayangan Halaman

Followers