Write a C# program to create a static function factorial and calculate factorial of the number.

Write a C# program to create a static function factorial and calculate the factorial of the number.

Write a C# program to create a static function factorial and calculate factorial of the number.

Object:

Write a program to explain the method in C#. Create a static function factorial() that accepts a number
from the user and returns the factorial of the number. C# Projects with Source Code

Code:

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

namespace LAB_4a

{

    class factorial

    {
         public static void fac()

        {

            int i, num, fact = 1;

            Console.WriteLine(“Enter Any Number: “);

            num = Convert.ToInt32(Console.ReadLine());

            for (i = num; i >= 1; i–)

            {
                 fact = fact * I;
             }

            Console.WriteLine(“\nFactorial of given Number is : ” + fact);

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

           factorial.fac();
           Console.ReadKey();

        }

    }

}

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

namespace LAB_4a
{
    class factorial
    {
        public static void fac()
        {
            int i, num, fact = 1;
            Console.WriteLine("Enter Any Number: ");
            num = Convert.ToInt32(Console.ReadLine());
            for (i = num; i >= 1; i--)
            {
                fact = fact * i;
            }
            Console.WriteLine("\nFactorial of given Number is : " + fact);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            factorial.fac();
            Console.ReadKey();

        }
    }
}

Output:

Write a C# program to create a static function factorial and calculate factorial of the number.

Another C# Program: C# Program Calculating the Area of a Rectangle

Another C# Program: C# Program that Subtracts two user-defined numbers

Another C# Program: C# Program Create a class student with a data members name and calculate marks and percentage.

Another C# Program: C# program to count vowels in a string

Leave a Comment

Your email address will not be published. Required fields are marked *