Saturday 15 October 2011

(k) 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.


#include <stdio.h>
#include<conio.h>
int main()
{
    int amount;
  
    // taking input   
    printf("Enter the amount to be withdrawn (in hundreds): ");
    scanf("%d",&amount);
   
    //calculations
    printf("\n\nRequired notes of Rs. 100  :  %d", amount / 100);
    // e.g. if amount entered is 987 then 987 / 100 will answer 9 (because amount is an intiger variable) 
   
    printf("\n\nRequired notes of Rs. 50   :  %d", (amount % 100) / 50);
    //e.g. 987 % 100 will answer 87 and then 87 / 50 will answer 1.
   
    printf("\n\nRequired notes of Rs. 10   :  %d", (((amount % 100) % 50) / 10));
   
    printf("\n\nAmount still remaining Rs. :  %d", (((amount % 100) % 50) % 10));
   
    getch();
}


13 comments:

  1. Replies
    1. to get our result on screen
      by this we comand the compiler to print the screen

      Delete
    2. getch(); command is use to get output on screen, its command is written in header file conio.h, through this we command the compiler to print on screen

      Delete
    3. hi KHURRAM ALI

      basically getch() is a pre-defined function used to take a character as an input ,but using this function at the end of a program has a different aspect as we use it here to hold the screen till the user presses any key to return to the code screen

      Delete
    4. Yes you gave the right answer .

      Delete
  2. This is very educational content and written well for a change.650 euros to dollars It's nice to see that some people still understand how to write a quality post!

    ReplyDelete
  3. If you people don't mind is there anyone who can explain this program.

    ReplyDelete
    Replies
    1. Assume amount to be 3287,
      1. To obtain number of 100th notes we divide the amount by 100.(i.e 3287/100=>total of 32 notes of 100Rs.
      2. To obtain remaining amount i.e 87.Apply % with 100.Since,87 is remainder of (3287/100)
      Now,obtain number of 50th notes by dividing remainder(87) with 50
      3.To obtain number of 10th notes .Get remaining amount i.e(remainder of 87/50)=>17.
      Now,Divide 17 with 10
      4.At last, the reamining amount that cannot be further distributed from given denomination with 10,50,100 is given by :
      3287 % 100 % 50 %10
      87 17 7

      Delete
  4. Is this Coin Change Problem ?

    ReplyDelete
  5. i need algorithm in python forcashier has currency notes of denominations Rs.10, Rs. 50 and Rs. 100. If the amount to be
    withdrawn is input in hundreds, find the total number of notes of each denomination the
    cashier will have to give to the withdrawer.

    ReplyDelete
  6. Under the header file we will also use clrscr() {to clear the console screen} along with getch()?

    ReplyDelete