10 ตุลาคม 2551

โปรแกรมเพื่อรับจำนวนเงินบาท

#include "stdio.h"
#include "conio.h"
void main() 
{
int money,bank1000 =0 ,bank500 =0 ,bank100 =0,bank50 =0 ,bank20=0,bank10 =0 ,bank5 =0 ,bank1 = 0;
clrscr();
printf("Money = ");scanf("%d",&money);
if (money >= 1000)
{
  bank1000 = div(money,1000);
  money = money - (bank1000 * 1000);
}
if (money >= 500)
{
  bank500 = div(money,500);
  money = money - (bank500 * 500);
}
if (money >= 100)
{
  bank100 = div(money,100);
  money = money - (bank100 * 100);
}
if (money >= 50)
{
  bank50 = div(money,50);
  money = money - (bank50 * 50);
}
    if (money >= 20)
{
  bank20 = div(money,20);
  money = money - (bank20 * 20);
}
if (money >= 10)
{
bank10 = div(money,10);
money = money - (bank10 * 10);
   }
if (money >= 5)
{
bank5 = div(money,5);
money = money - (bank5 * 5);
if (money >= 0) bank1 = money;
else
{
printf("Money Incorret Type\n");
printf("Press Any Key To Exit\n");
exit();
    }
printf(" 1000 = %d\n",bank1000);
printf("  500 = %d\n",bank500);
printf("  100 = %d\n",bank100);
printf("   50 = %d\n",bank50);
printf("   20 = %d\n",bank20);
printf("   10 = %d\n",bank10);
printf("    5 = %d\n",bank5);
printf("    1 = %d\n",bank1);
   getch();
}