Q) Write a program to determine the smallest number of notes of different domination that are required for an amount input by a user. Assume that the notes are in domination of 100,50,20,10,5,2 and 1.
Code:
#include<stdio.h>
int main()
{
int amount,x;
int dom[7]={100,50,20,10,5,2,1};
int num[7]={0,0,0,0,0,0,0};
printf("Enter the amount:");
scanf("%d",&amount);
x=amount;
for(int i=0;i<7;i++){
while(x>=dom[i]){
x-=dom[i];
num[i]++;
}
}
printf("The min no of note for amount % d is when there are:\n",amount);
for(int j=0;j<7;j++){
if (num[j]!=0)
printf("%d notes of %d\n",num[j],dom[j]);
}
return 0;
}
I would like to know if this is good or someother more efficient code can be written.
Thanks