Codingan PAA (Dengan metode Greedy)


#include<stdio.h>
#include<conio.h>
#define size 99
void sort (int[],int);
main()
{
clrscr();
int x[size],i,n,uang,hasil[size];
printf(“\ 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 :”);
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;
}
}
}
}

This entry was posted in LA.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s