Home > Back-end >  C cents change
C cents change

Time:09-22

To convert n cents to 25,10,5 and 1 cent COINS in total how many kinds of transformation methods?
The results are as follows:

25
13
If n is not between 0 ~ 99, the output message "the money is invalid!"
The results are as follows:

101
The money is invalid!

Input format:
Integers, said the United States score
Enter an integer between may not be 13 [0], between input is not in the area, the output is "the money is invalid!" ,

The output format:
Conversion method number or message "the money is invalid!" (without the quotation marks, only one space between words)

Solution: use a for loop

# include
using namespace std;

Int main ()
{
Int n, I, j, t, num=0;
25,10,5 int a [3]={};
Cin & gt;> n;
If (n> 99 | | n<0)
Cout & lt; & lt; "The money is invalid".
The else {
For (j=n/a, [0]. J>=0; J -)//j said 25 cents number
{
Int temp1=n - j * a [0];//temp1 said j. zhang after 25 cents to remove the remaining
For (t=temp1/a, [1]. T>=0; T -)//t said 10 cents number
{
Int temp2=temp1 - t * a, [1].//remove j 25 cents and a card after 10 cents remaining
For (I=temp2/a, [2]. I>=0; I -)//I said five cents a piece count
{
num++;//num representation for
}
}
}
Cout & lt; & lt; Num & lt; & lt; endl;
}
return 0;
}

  • Related