Saturday, January 30, 2010

CHAP 1[H]k Currency denomination problem

A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.

Note: So if its $900 the input value is 9 and if its $1970 input is 19.7

void main()
{
float t,_10,_50,_100;
int _11,_51,_101;
printf("\nInput notes in hundreds");
scanf("%f",&t);

_100=t/100;
_101=_100;
_50=(t-_101*100.0)/50;
_51=_50;
_10=(t-(_101*100.0+_51*50.0))/10;
_11=_10;
printf("\n_100 is %f\n_101 is %d",_100,_101);
printf("\nThe no of $100 notes is %d\nThe no of $50 notes is %d\nThe no of $10 notes is %d",_101,_51,_11);
}

2 comments:

  1. Try this less complicated and never needs to declare float:

    main( )
    {

    int amount,hu,fif,ten,rest;
    printf("Enter the amount in hundred for Withdraw");
    scanf("%d",&amount);
    //100 note
    hu=amount/100;
    rest=amount-(hu*100);
    //50 note
    fif=rest/50;
    rest=amount-(hu*100+fif*50);
    //10 note
    ten=rest/10;
    printf("You Will get Not of\n100=%d \n50=%d \n10=%d \nProgrammed by Jeet",hu,fif,ten);

    }

    ReplyDelete
  2. #include
    #include

    void main()
    {
    int amt,no_100,no_50,no_10;
    clrscr();
    printf("Enter the amount to divide:");
    scanf("%d",&amt);

    no_100=amt/100;
    amt=amt%100;

    no_50=amt/50;
    amt=amt%50;

    no_10=amt/10;

    printf("\n100's currency:%d",no_100);
    printf("\n50's currency:%d",no_50);
    printf("\n10's currency:%d",no_10);

    getch();
    }

    ReplyDelete