100 元錢,由二元、一元、五角面幣 100 張組成,問各有多少張?

#include "stdafx.h"
#include <iostream>
#define MAXPAPER 100


int _tmain(int argc, _TCHAR* argv[])
{
	//100張   2元+1元+0.5元     100元

	//2x + 1y + 1/2z = 100
	//x + y + z = 100
	//x = 1/2z
	//2x = z
	int iTwo =  1,iOne, iHalf = 2 , iCount = 0;
	while(true)
	{
		iOne = MAXPAPER - iHalf - iTwo;
		if (iOne < 0)
		{
			break;
		}
		printf("2 yuan is %d , 1 yuan is %d , 0.5 yuan is %d\n",iTwo,iOne,iHalf);
		iTwo ++;
		iHalf = iHalf + 2;
		iCount++;
	}
	printf("Count all method is %d\n",iCount);
	system("pause");
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章