1
我必須打印不同鈔票的組合,一個人應該付給收銀員。計劃首先要求支付總額,然後提出他擁有的不同教派的註釋。問題是,我只能打印一種貨幣組合,但通過以下代碼獲取所有組合(如往常一樣)。使用嵌套循環僅打印一個組合
#include <stdio.h>
int main(void)
{
int hundred,fifty,ten,total,hund,fif,t;
printf ("Enter amount to be paid:");
scanf ("%d",&total);
printf ("\n\nHow many currency notes do you have?\nEnter 100,50 and 10 Rupee Notes Respectively:\n");
scanf ("%d %d %d",&hund,&fif,&t);
printf ("\t\t\tPossible combination for Rs=%d/- \n",total);
for (hundred=0; hundred<=hund; hundred++)
{
for (fifty=0; fifty<=fif; fifty++)
{
for (ten=0; ten<=t; ten++)
{
if ((hundred*100+fifty*50+ten*10)==total)
{
printf("\n\n Hundred rupees notes=%d, 50 rupees notes=%d, 10 rupees notes=%d",hundred,fifty,ten);
}
}
}
}
getch();
return 0;
}
想想你如何使它無循環和更少的貨幣數 – Pradheep 2014-09-21 12:47:08
'printf'和'return 0;' – BLUEPIXY 2014-09-21 12:50:31
「代碼工作正常」 - 在清理縮進時,我發現一個流浪的' {'。請確保您用來顯示問題的代碼本身是正確的。 – usr2564301 2014-09-21 12:51:53