C Programming

Solved Example

Practice Questions

Exercise Question

Find Indian currency dominants

Objective

Input an amount and find the possible dominants in Indian currency.

Program / Solution:

#include<stdio.h>

int main() {
	int amt;
	int tth,th,fh,twoh,h,fifty,twenty,ten,five,two,one;
	
	printf("Enter the amount to withdraw: ");
	scanf("%d",&amt);
	
	tth = amt / 2000; // find the possible pair of 2000
	amt = amt % 2000; // Remaining amount after excluding 2000 possible pairs
	
	th = amt / 1000; // find the possible pair of 1000
	amt = amt % 1000; // Remaining amount after excluding 1000 possible pairs
	
	fh = amt / 500; // find the possible pair of 500
	amt = amt % 500; // Remaining amount after excluding 500 possible pairs
	
	twoh = amt / 200; // find the possible pair of 200
	amt = amt % 200; // Remaining amount after excluding 200 possible pairs
	
	h = amt / 100; // find the possible pair of 100
	amt = amt % 100; // Remaining amount after excluding 100 possible pairs
	
	fifty = amt / 50; // find the possible pair of 50
	amt = amt % 50; // Remaining amount after excluding 50 possible pairs
	
	twenty = amt / 20; // find the possible pair of 20
	amt = amt % 20; // Remaining amount after excluding 20 possible pairs
	
	ten = amt / 10; // find the possible pair of 10
	amt = amt % 10; // Remaining amount after excluding 10 possible pairs
	
	five = amt / 5; // find the possible pair of 5
	amt = amt % 5; // Remaining amount after excluding 5 possible pairs
	
	two = amt / 2; // find the possible pair of 2
	amt = amt % 2; // Remaining amount after excluding 2 possible pairs
	
	one = amt; // Remaining pair automatically treated pair of 1.
	
	printf("2000 * %d = %d\n",tth,tth * 2000);
	printf("1000 * %d = %d\n",th,th * 1000);
	printf("500 * %d = %d\n",fh,fh * 500);
	printf("200 * %d = %d\n",twoh,twoh * 200);
	printf("100 * %d = %d\n",h,h * 100);
	printf("50 * %d = %d\n",fifty,fifty * 50);
	printf("20 * %d = %d\n",twenty,twenty * 20);
	printf("10 * %d = %d\n",ten,ten * 10);
	printf("5 * %d = %d\n",five,five * 5);
	printf("2 * %d = %d\n",two,two * 2);
	printf("1 * %d = %d\n",one,one);
	
	return 0;
}

Sample Output:

Enter the amount to withdraw: 15742
2000 * 7 = 14000
1000 * 1 = 1000
500 * 1 = 500
200 * 1 = 200
100 * 0 = 0
50 * 0 = 0
20 * 2 = 40
10 * 0 = 0
5 * 0 = 0
2 * 1 = 2
1 * 0 = 0