Sunday 4 March 2018

Finding the Number of 500,100,50,20,10,5,2 and 1 Rupee Notes in a Given Amount.

# include <stdio.h> 
# include <conio.h> 
void main() 
{ 
 int rs, a, b, c, d, e, f, g, h ; 
 clrscr() ; 
 printf("Enter the amount in Rupees : ") ; 
 scanf("%d", &rs) ; 
 while(rs >= 500) 
 { 
  a = rs / 500 ; 
  rs = rs % 500;
  printf("\nThe no. of five hundreds are : %d", a) ; 
  break ; 
 } 
 while(rs >= 100) 
 { 
  b = rs / 100 ; 
  rs = rs % 100;
  printf("\n\nThe no. of hundreds are : %d", b) ; 
  break ; 
 } 
 while(rs >= 50) 
 { 
  c = rs / 50 ;
  rs = rs % 50; 
  printf("\n\nThe no. of fifties are : %d", c) ; 
  break ; 
 } 
 while(rs >= 20) 
 { 
  d = rs / 20 ; 
  rs = rs % 20;
  printf("\n\nThe no. of twenties are : %d", d) ; 
  break ; 
 } 
 while(rs >= 10) 
 { 
  e = rs / 10 ; 
  rs = rs % 10;
  printf("\n\nThe no. of tens are : %d", e) ; 
  break ; 
 } 
 while(rs >= 5) 
 { 
  f = rs / 5 ; 
  rs = rs % 5;
  printf("\n\nThe no. of fives are : %d", f) ; 
  break ; 
 } 
 while(rs >= 2) 
 { 
  g = rs / 2 ; 
  rs = rs % 2;
  printf("\n\nThe no. of Twos are : %d", g) ; 
  break ; 
 } 
 while(rs >= 1) 
 { 
  h = rs / 1 ; 
  rs = rs % 1;
  printf("\n\nThe no. of ones are : %d", h) ; 
  break ; 
 } 
 getch() ; 
}

Output of above program is

Enter the amount in Rupees : 698

The no. of five hundreds are : 1

The no. of hundreds are : 1 

The no. of fifties are : 1              
                                        
The no. of twenties are : 2 
                                        
The no. of fives are : 1 
                                        
The no. of Twos are : 1 

The no. of ones are : 1

0 comments:

Post a Comment

Tech UOG