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

  • Opera 43.0.2442.991 22 Februari 2017
    Opera is a secure web browser that is both fast and rich in features. It has a slick interface that embraces a modern, minimalist look, coupled with stacks of tools to make browsing more enjoyable. These include such tools as Speed Dial, which houses...
  • Acronis True Image 2017 Build 8029 22 Februari 2017
    Acronis True Image 2017 is a new, multi-platform edition of the trusted backup tool. The application can work with both local and cloud storage, and can be configured to backup your whole disk or just single files or folders. It brings faster disk ...
  • Kindle for PC 1.19.3 Build 46099 22 Februari 2017
    Kindle for PC is a free application that lets you read Kindle books on your PC. Read Kindle Books on Your Computer Get the best reading experience available on your PC. No Kindle required. Access your Kindle books even if you don't have your Kin...
  • Far Manager 3.0.4900.0 22 Februari 2017
    Far Manager is an application for managing files and archives in Windows operating systems. Far Manager works in text mode and provides a simple and intuitive interface for performing actions. Key Features Include: Viewing files and directories; ...
  • Adobe Acrobat Reader DC 2015.023.20070 22 Februari 2017
    Adobe Acrobat Reader DC is the industry standard for viewing, printing, signing and commenting on PDF documents. It's the only PDF viewer available*, which is able to open and interact with all types of PDF content, including forms and multimedia. ...

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: