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

  • Save To Pocket 2.1.48 19 Oktober 2017
    The Save to Pocket Extension for Chrome is one of the best ways to save articles, videos and other important content. Using the extension is really easy; when you find something in Chrome that you want to view later, put it in Pocket! The Save to Poc...
  • SaferPass 6.3.3 19 Oktober 2017
    SaferPass Password Manager makes life easy by ensuring you never forget another password! With SaferPass you have the ability to generate strong password, which you don't have to remember. SaferPass is able to secure your online accounts and aut...
  • Google Translate 2.0.7 19 Oktober 2017
    The Google Translate extension will allow you to view numerous languages easily as you browse the web. Simply highlight or right-click on a portion of text and then click on Translate icon next to it to translate it to the language that you need. If ...
  • Google Calendar 2.8 19 Oktober 2017
    If you use Google's Chrome browser and you use Google's Calendar then, quite simply, you need to install the free Google Calendar extension for Chrome. With the Google Calendar extension installed, you will be able to access your Google Calendar ap...
  • Notepad3 2.17.1016.610 19 Oktober 2017
    Notepad3 is a revamp of the standard, vanilla offering Windows Notepad that comes with Microsoft’s operating system. Notepad3 is a fast and lightweight Scintilla-based text editor with syntax highlighting capability. Although it has a small footpri...

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: