The My Opera forums have been replaced with forums.opera.com. Please head over there to discuss Opera's products and features

See the new Forums

Một số bài tập tham thảo theo yêu cầu của thầy: P1 - Tính Giai thừa

Forums » Học actionscript3 » Bài tập actionscript tham khảo

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

16. November 2011, 04:12:32

Một số bài tập tham thảo theo yêu cầu của thầy: P1 - Tính Giai thừa

Gia thừa là khi bạn nhập vào 1 số n=10 thì giai thừa của nó là :giaithua= 1*2*3*4*5*6*7*8*9*10

*Ý tưởng giải như sau:
-cho 1 vòng lặp chạy từ 1->n
-Và cứ mỗi vòng lặp ta lại : giaithua=giaithua*i;

Code tổng quát như sau:
function tinhgiaithua(n:int):Number
{
	var luythua:Number; luythua=1;
	for(var i:int=1;i<n+1;i++)
	{
		luythua=luythua*i;
	}
	return luythua;1
}
trace(tinhgiaithua(10));					

Forums » Học actionscript3 » Bài tập actionscript tham khảo