Header Ads

Header ADS

Solution of URI 1021::Banknotes and Coins

Before seeing the solution make sure that you have tried enough. Don’t copy the whole code, just find out the logic. If you feel any problemyou will inform me by comment.




#include <stdio.h>
int main()
{
    double  N;
    int n100,n50,n20,n10,n5,n2,n1,c50,c25,c10,c05,c01;

    scanf("%lf",&N);

    c01=N*100;
    n100=c01/10000;
    c01=c01%10000;
    n50=c01/5000;
    c01=c01%5000;
    n20=c01/2000;
    c01=c01%2000;
    n10=c01/1000;
    c01=c01%1000;
    n5=c01/500;
    c01=c01%500;
    n2=c01/200;
    c01=c01%200;
    n1=c01/100;
    c01=c01%100;
    c50=c01/50;
    c01=c01%50;
    c25=c01/25;
    c01=c01%25;
    c10=c01/10;
    c01=c01%10;
    c05=c01/5;
    c01=c01%5;



    printf("NOTAS:\n");

    printf("%d nota(s) de R$ 100.00\n",n100);
    printf("%d nota(s) de R$ 50.00\n",n50);
    printf("%d nota(s) de R$ 20.00\n",n20);
    printf("%d nota(s) de R$ 10.00\n",n10);
    printf("%d nota(s) de R$ 5.00\n",n5);
    printf("%d nota(s) de R$ 2.00\n",n2);

    printf("MOEDAS:\n");

    printf("%d moeda(s) de R$ 1.00\n",n1);
    printf("%d moeda(s) de R$ 0.50\n",c50);
    printf("%d moeda(s) de R$ 0.25\n",c25);
    printf("%d moeda(s) de R$ 0.10\n",c10);
    printf("%d moeda(s) de R$ 0.05\n",c05);
    printf("%d moeda(s) de R$ 0.01\n",c01);

    return 0;
}


No comments

Theme images by konradlew. Powered by Blogger.