কম্পিউটার টিউটোরিয়াল

C#-এ ফ্যাক্টোরিয়াল গণনার তিনটি ভিন্ন পদ্ধতি

C#-এ ফ্যাক্টোরিয়াল গণনা করার জন্য আপনি নিচের তিনটি পদ্ধতির যেকোনো একটি ব্যবহার করতে পারেন:

ফর লুপ ব্যবহার করে ফ্যাক্টোরিয়াল গণনা

উদাহরণ

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace factorial { 
    class Test { 
        static void Main(string[] args) { 
            int i, res; 
            int value = 5; 
            res = value; 
            for (i = value - 1; i >= 1; i--) { 
                res = res * i; 
            } 
            Console.WriteLine("\nFactorial of " + value + " = " + res); 
            Console.ReadLine(); 
        } 
    } 
}

আউটপুট

Factorial of 5 = 120

হোইল লুপ ব্যবহার করে ফ্যাক্টোরিয়াল গণনা

উদাহরণ

using System; 

namespace MyApplication { 
    class Factorial { 
        public int display(int n) { 
            int res = 1; 
            while (n != 1) { 
                res = res * n; 
                n = n - 1; 
            } 
            return res; 
        } 
        static void Main(string[] args) { 
            int value = 5; 
            int ret; 
            Factorial fact = new Factorial(); 
            ret = fact.display(value); 
            Console.WriteLine("Value is : {0}", ret); 
            Console.ReadLine(); 
        } 
    } 
}

আউটপুট

Value is : 120

রিকার্শন ব্যবহার করে ফ্যাক্টোরিয়াল গণনা

উদাহরণ

using System; 

namespace MyApplication { 
    class Factorial { 
        public int display(int n) { 
            if (n == 1) 
                return 1; 
            else 
                return n * display(n - 1); 
        } 
        static void Main(string[] args) { 
            int value = 5; 
            int ret; 
            Factorial fact = new Factorial(); 
            ret = fact.display(value); 
            Console.WriteLine("Value is : {0}", ret); 
            Console.ReadLine(); 
        } 
    } 
}

আউটপুট

Value is : 120
  1. উইন্ডোজ ১₀ কমান্ড প্রম্পট খোলার ৫টি বিশ্বস্ত পদ্ধতি

  2. জুমে পার্টিসিপ্যান্ট মিউট করার পদ্ধতি: কার্যকর গাইড

  3. উইন্ডোজ ১০-এ প্রক্সি সেটিংস ডিজেবল করার ৩টি নির্ভরযোগ্য উপায়

  4. উইন্ডোজ ১₀-এ Guest Account ইনেবল করুন: Home এবং Pro এডিশনের জন্য ধাপে ধাপে গাইড