Miscellaneous > Programming & Networking

Programming Challenge N

(1/3) > >>

TheQuirk:
Okay, this one's a bit easier than usual.

Find the minimal number of coins you'd need to get n cents (assume dollar, five dollar, etc. coins don't exist).

For example, if n = 19, the answer is 6 (a nickle, a dime, and four pennies).

worker201:
Wow, that is a hell of a lot easier than your other challenges.  I wrote a program to do this using C++ when I was in college - using Borland Turbo C++ for MS-DOS (this was when Windows 95 was not yet widespread).

H_TeXMeX_H:
Perhaps I'll actually attempt this one. Don't have time now tho ... maybe later today.

solemnwarning:

--- Code: ---#define n 19

int count = 0;
int count_1 = 0;
int count_2 = 0;
int count_5 = 0;
int count_10 = 0;
int count_20 = 0;
int count_50 = 0;
while(count < n) {
if(count + 50

H_TeXMeX_H:
Here it is in shell script (just for fun):


--- Code: ---#!/bin/sh

printf "Enter the number of cents ==> "
read number

coins=0

for i in 50 25 10 5 1
do
 while test "$number" -ge "$i"
 do
  let coins++
  let number-=$i
 done
done

echo "The answer is $coins coins"

exit 0

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version