اكتب برنامج C لقراءة مبلغ (عدد صحيح) ويقوم بتقسيم المبلغ إلى أصغر عدد ممكن من الأوراق النقدية

  • برمجة
  • برمجة سي c

اكتب برنامج C لقراءة مبلغ (عدد صحيح) ويقوم بتقسيم المبلغ إلى أصغر عدد ممكن من الأوراق النقدية

مثال عن الخرج المتوقع :

Input the amount: 375
There are:
3 Note(s) of 100.00
1 Note(s) of 50.00
1 Note(s) of 20.00
0 Note(s) of 10.00
1 Note(s) of 5.00
0 Note(s) of 2.00
0 Note(s) of 1.00

الأجوبة

/*Write a C program to read an amount (integer value) and break the amount into smallest possible number of bank notes*/

#include 
int main() {
	int amt, total;
	printf("Input the amount: ");
	scanf("%d",&amt);
	
	total = (int)amt/100;
	
	printf("There are: ");
	
	printf("\n%d Note(s) of 100.00\n", total);
	
	amt = amt-(total*100);
	
	total = (int)amt/50;
	
	printf("%d Note(s) of 50.00\n", total);
	
	amt = amt-(total*50);
	
	total = (int)amt/20;
	
	printf("%d Note(s) of 20.00\n", total);
	
	amt = amt-(total*20);
	
	total = (int)amt/10;
	
	printf("%d Note(s) of 10.00\n", total);
	
	amt = amt-(total*10);
	
	total = (int)amt/5;
	
	printf("%d Note(s) of 5.00\n", total);
	
	amt = amt-(total*5);
	
	total = (int)amt/2;
	
	printf("%d Note(s) of 2.00\n", total);
	
	amt = amt-(total*2);
	
	total = (int)amt/1;
	
	printf("%d Note(s) of 1.00\n", total);
	
	return 0;
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...