-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpraktikum3CoinSwap.cpp
58 lines (57 loc) · 1.27 KB
/
praktikum3CoinSwap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <conio.h>
#define size 99
void sort(int[], int);
int main()
{
int x[size], i, uang, n, k, hasil[size];
printf("\n Banyak Koin : ");
scanf("%d", &n);
printf("\n \n Masukan Jenis Koin : \n");
for (i = 1; i <= n; i++)
{
scanf("\n %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 Masukan Nilai yang dipecah : ");
scanf("%d", &uang);
printf("\n");
for (i = 1; i <= n; i++)
{
hasil[i] = uang / x[i];
uang = uang % x[i];
k = uang % x[i];
}
for (i = 1; i <= n; i++)
{
printf("Keping %d", x[i]);
printf("-an sebanyak : %d", hasil[i]);
printf("\n \n");
}
printf("sisanya adalah %d", k);
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;
}
}
}
}