Program to Find how many 5,2 and 1 rupee

Let us see a simple program to find, how many 5rupees, 2rupees and 1rupee are there in Rs.53. Number of 5,2,1 rupees note or coins in rs.53.

Array “rup” will be holding 5,2,1. If you want to find only number of 5 and 2 rupees then remove 1.  You also add a number to that array. Change accordingly.

class rupees
{
public static void main(String[] args)

{
	int rup[]={5,2,1};

	int i=0,num=53;

	while(num > 0)
	{
	    if(num/rup[i] > 0)
	    {
	    System.out.println(num/rup[i] + "- " + rup[i] + " rupees");

	    num=num-((num/rup[i])*rup[i]);

	    }
	    i++;
	}

   }
  }

 

Output displayed by the above program:

10 – 5 rupees
1   -  2 rupess
1   -  1 rupees