-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy path100-change.c
More file actions
59 lines (52 loc) · 872 Bytes
/
100-change.c
File metadata and controls
59 lines (52 loc) · 872 Bytes
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
59
/*
* File: 100-change.c
* Auth: Brennan D Baraban
*/
#include <stdio.h>
#include <stdlib.h>
/**
* main - Prints the minimum number of coins to
* make change for an amount of money.
* @argc: The number of arguments supplied to the program.
* @argv: An array of pointers to the arguments.
*
* Return: If the number of arguments is not exactly one - 1.
* Otherwise - 0.
*/
int main(int argc, char *argv[])
{
int cents, coins = 0;
if (argc != 2)
{
printf("Error\n");
return (1);
}
cents = atoi(argv[1]);
while (cents > 0)
{
coins++;
if ((cents - 25) >= 0)
{
cents -= 25;
continue;
}
if ((cents - 10) >= 0)
{
cents -= 10;
continue;
}
if ((cents - 5) >= 0)
{
cents -= 5;
continue;
}
if ((cents - 2) >= 0)
{
cents -= 2;
continue;
}
cents--;
}
printf("%d\n", coins);
return (0);
}