Q. Write a program in C to split a given amount of money into currency notes of different types using switch statement.
Solution:
Solution:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
long amount,leftout; | |
int i; | |
int note[] = {2000,500,200,100,50,20,10,5,2,1}; | |
int count[] = {0,0,0,0,0,0,0,0,0,0}; | |
printf("\nEnter amount: "); | |
scanf("%ld",&amount); | |
leftout = amount; | |
for(i=0;i<10;i++){ | |
switch(note[i]){ | |
case 2000: | |
count[i] = leftout / 2000; | |
leftout = leftout % 2000; | |
break; | |
case 500: | |
count[i] = leftout / 500; | |
leftout = leftout % 500; | |
break; | |
case 200: | |
count[i] = leftout / 200; | |
leftout = leftout % 200; | |
break; | |
case 100: | |
count[i] = leftout / 100; | |
leftout = leftout % 100; | |
break; | |
case 50: | |
count[i] = leftout / 50; | |
leftout = leftout % 50; | |
break; | |
case 20: | |
count[i] = leftout / 20; | |
leftout = leftout % 20; | |
break; | |
case 10: | |
count[i] = leftout / 10; | |
leftout = leftout % 10; | |
break; | |
case 5: | |
count[i] = leftout / 5; | |
leftout = leftout % 5; | |
break; | |
case 2: | |
count[i] = leftout / 2; | |
leftout = leftout % 2; | |
break; | |
case 1: | |
count[i] = leftout / 1; | |
leftout = leftout % 1; | |
break; | |
} | |
} | |
printf("\nAmount %ld contains the following notes:",amount); | |
for(i=0;i<10;i++) | |
if(count[i] > 0) | |
printf("\nRs. %d notes --> %d numbers",note[i],count[i]); | |
return 0; | |
} |
No comments:
Post a Comment