URI ONLINE JUDGE SOLUTION 1021 - Banknotes and Coins

Problem

Read a value of floating point with two decimal places. This represents a monetary value. After this, calculate the smallest possible number of notes and coins on which the value can be decomposed. The considered notes are of 100, 50, 20, 10, 5, 2. The possible coins are of 1, 0.50, 0.25, 0.10, 0.05 and 0.01. Print the message “NOTAS:” followed by the list of notes and the message “MOEDAS:” followed by the list of coins.

Input

The input file contains a value of floating point N (0 ≤ N ≤ 1000000.00).

Output


Print the minimum quantity of banknotes and coins necessary to change the initial value, as the given example.

sample input output

sample input output

Solution

#include<stdio.h>
int main()
{
    int c[12],n,f,i,num[] = {100,50,20,10,5,2,100,50,25,10,5,1};
    double x;
    scanf("%lf",&x);
    n = x;
    f = x*100;
    f = f%100;
    printf("NOTAS:\n");
    for(i = 0;i<6;i++)
    {
        c[i] = n/num[i];
        n = n%num[i];
        printf("%d nota(s) de R$ %d.00\n", c[i], num[i]);
    }
    if(n == 1)
    f = f+100;
    printf("MOEDAS:\n");
    for(i = 6;i<12;i++)
    {
        c[i] = f/num[i];
        f = f%num[i];
        printf("%d moeda(s) de R$ %0.2lf\n", c[i], num[i]/100.0);
    }
    return 0;

}

Comments

Post a Comment

Popular posts from this blog

URI ONLINE JUDGE SOLUTION 1040 - Average 3

URI ONLINE JUDGE SOLUTION 1036 - Bhaskara's Formula