Ticker

6/recent/ticker-posts

ATM - Count minimum no. of notes for given amount Program


Enter the sum to find number of notes -

Q- Write a C program to input amount from user and print minimum number of notes (Rs. 2000, 500, 100, 50, 20, 10, 5, 2, 1) required for the amount.

#include <stdio.h>
int main()
{
  int a,two,five,hun,fif,twe,ten,fi,to,one;
  scanf("%d",&a);
  two=a/2000; a=a%2000;
  five=a/500 ; a=a%500;
  hun=a/100; a=a%100;
  fif=a/50; a=a%50;
  twe=a/20; a=a%20;
  ten=a/10; a=a%10;
  fi=a/5 ; a=a%5;
  to=a/2; a=a%2;
  one=a/1;
  printf("%d %d %d %d %d %d %d %d %d",two,five,hun,fif,twe,ten,fi,to,one);
return 0;
}

Output -

23000
11 2 0 0 0 0 0 0 0 

Post a Comment

0 Comments