Koin vs Algoritma Greedy

Tinggalkan komentar

29 Oktober 2012 oleh Rizky Zakaria

Diartikel ini, saya akan membagikan “listing program” dan “output program” perhitungan koin dengan menggunakan proses Algoritma Greedy.

Ini Listingnya:

#include<stdio.h>

#include<conio.h>

#define size 99

void sort(int[], int);

main()

{

int x[size],i,n,uang,hasil[size];

printf(“\n Banyak Koin :”);

scanf(“%d”, &n);

printf(“\n \n Masukkan Jenis Koin : \n”);

for(i=1;i<=n;i++)

{

scanf(“%d”, &x[i]);

}

sort(x,n);

printf(“\n Koin yang Tersedia \n :”);

for(i=1;i<=n;i++)

{

printf(“%d”, x[i]);

printf(“\n”);

}

printf(“\n”);

printf(“\n Masukkan Nilai yang Dipecah :”);

scanf(“%d”, &uang);

printf(“\n”);

for(i=1;i<=n;i++)

{

hasil[i]=uang/x[i];

uang=uang%x[i];

}

for(i=1;i<=n;i++)

{

printf(“Keping %d”, x[i]);

printf(“-an sebanyak : %d”, hasil[i]);

printf(“\n \n”);

}

getch();

return 0;

}

void sort(int a[], int siz)

{

int pass,hold,j;

for(pass=1;pass<=siz-1;pass++)

{

for(j=0;j<=siz-2;j++)

{

if(a[j+1] < a[j+2])

{

hold=a[j+1];

a[j+1]=a[j+2];

a[j+2]=hold;

}}}}

FYI: stdio.h & conio.h itu “header” buat memasukkan suatu file library dalam program yang dibuat.

void sort diperlukan untuk difenisikan setelah fungsi main() atau biasanya buat mensorting.

for(pass=1;pass<=siz-1;pass++)

for(j=0;j<=siz-2;j++)

if(a[j+1] < a[j+2])

hold=a[j+1];

a[j+1]=a[j+2];

a[j+2]=hold; (inti dari istilah ALGORITMA GREEDY ada di dilisting dari “for(pass” sampai “a[j+”. Jadi algoritma ini nggak mau ribet, langsung dicari yang terbesar aja.

 

Dan ini gambar outputnya:

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

Masukkan alamat surat elektronik Anda untuk mengikuti blog ini dan menerima pemberitahuan tentang tulisan baru melalui surat elektronik.

Bergabunglah dengan 1 pengikut lainnya

My Profile

Tanggal/Bulan/Tahun

Oktober 2012
S S R K J S M
« Sep   Des »
1234567
891011121314
15161718192021
22232425262728
293031  

7zip (Alternatif Selain WinRAR)

RSS detiksepakbola

RSS File Hippo

  • Spotify 1.0.44.100 9 Desember 2016
    With Spotify, it’s easy to find the right music for every moment – on your phone, your computer, your tablet and more. There are millions of tracks on Spotify. So whether you’re working out, partying or relaxing, the right music is always at your fi...
  • StressMyPC 2.91 9 Desember 2016
    If you need to test your computer's performance to ensure it is running at optimal capacity, then it is a good idea to run a stress test and analyze the results. StressMyPC is a small, lightweight and useful tool for the job. It actually does not req...
  • Calibre 2.74.0 64-bit 9 Desember 2016
    Calibre is a complete e-book library manager that lets you totally organize your collection. With Calibre you can convert your books to multiple formats, and then sync with all of your devices. KEY FEATURES INCLUDE: Library management. Calibre ...
  • Calibre 2.74.0 32-bit 9 Desember 2016
    Calibre is a complete e-book library manager that lets you totally organize your collection. With Calibre you can convert your books to multiple formats, and then sync with all of your devices. KEY FEATURES INCLUDE: Library management. Calibre...
  • LastPass: Free Password Manager 4.1.34 9 Desember 2016
    LastPass is an award-winning password manager that can save your passwords and provide you with secure access from every computer and mobile device you have. With LastPass you need only remember one password - your LastPass master password. With t...

RSS detikInet

  • Sebuah galat telah terjadi; umpan tersebut kemungkinan sedang anjlok. Coba lagi nanti.

RSS detikOto

  • Sebuah galat telah terjadi; umpan tersebut kemungkinan sedang anjlok. Coba lagi nanti.
%d blogger menyukai ini: