🔒 Closed Just a little help sa c# mga boss

Status
Not open for further replies.

RedKind

Enthusiast
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.

About this Thread

  • 4
    Replies
  • 2K
    Views
  • 5
    Participants
Last reply from:
mrHazan

Trending Topics

Online now

Members online
692
Guests online
5,082
Total visitors
5,774

Forum statistics

Threads
2,326,146
Posts
29,227,189
Members
1,167,936
Latest member
kitoy86
Back
Top