Factorial of a number


/ Published in: ActionScript 3
Save to your folder(s)

Looking forward for more optimized solution for the same


Copy this code and paste it in your HTML
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
  3. <mx:Script>
  4. <![CDATA[
  5. var num:Number = 10;
  6. public function init():void{
  7. factor(num);
  8. txt.text = factor(num).toString();
  9. }
  10.  
  11. public function factor(num:Number):Number{
  12. var mul:Number = 1;
  13. for(var i=2;i<=num;i++){
  14. mul *= i;
  15. txt.text += "\n >>"+mul;
  16. }
  17. return mul;
  18. }
  19. ]]>
  20. </mx:Script>
  21. <mx:TextArea x="118" y="57" width="553" height="412" id="txt"/>
  22. </mx:Application>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.