What's new

Closed Just a little help sa c# mga boss

Status
Not open for further replies.

RedKind

Addict
Joined
Mar 2, 2017
Posts
207
Reaction
29
Points
106
mga boss
kasi binigay samen tong code tas 720 yung lumalabas di ko alam kung bakit ang hirap nya i analyze e

Code:
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace eLMSActivity3

{

    class Program

    {

        static int Fact(int num) {

            if (num == 1)

                return 1;

            else return num * Fact(num - 1);

        }

        static void Main(string[] args)

        {

            Console.WriteLine(Fact(6));

        }

    }

}


bali output nyan 720 pwede po pahelp whyy
 
Recursion kasi yan or tail recursion.
Ibig sabihin, ini-execute yung function hanggat hindi nasasatify yung conditional statement sa loob niya

Ito yung code na ine-execute niya ng maraming ulit, parang for-loop
Code:
        static int Fact(int num) {

            if (num == 1)

                return 1;

            else return num * Fact(num - 1);

        }

basically ang ginagawa lang niyan kinukuha lang yung factorial ng 6.
 
Madali lang yan.. pasok lang yan ng pasok..

magdebug ka para matrace mo line by line..

anyway you will learn how to understand it soon..
 
Aralin mo paano yung concept ng factorial tapos maiintindihan mo na yan.
Bale sa main function mo ang 6! (6 factorial) yung example. Try mo mas maliit mga 3! to 4! para maintindihan mo flow ng code.
 
Status
Not open for further replies.

Similar threads

Back
Top