Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Program for factorial of a number in c#

// C# program to find factorial
// of given number
using System;
 
class Test {
    // method to find factorial
    // of given number
    static int factorial(int n)
    {
        if (n == 0)
            return 1;
 
        return n * factorial(n - 1);
    }
 
    // Driver method
    public static void Main()
    {
        int num = 5;
        Console.WriteLine("Factorial of "
                          + num + " is " + factorial(5));
    }
}
 
// This code is contributed by vt_m
Comment

factorial n using class in c#

using System;
public class Program
{
	public int findFact(int n)
	{
		int i, f = 1;

		for (i = 1; i <= n; i++)
		{
			f = f * i;
		}
		return f;
	}

	public static void Main(string[] args)
	{
		int x, f;

		Console.Write("Enter a number:");
		x = Convert.ToInt32(Console.ReadLine());

		Program obj = new Program();
		f = obj.findFact(x);

		Console.WriteLine("Factorial is:" + f);
	}
}
Comment

Factorial C#

int Factorial(int n)
{
    if (n == 1) return 1;

    return n * Factorial(n - 1);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: play a sound c# 
Csharp :: unity find gameobject by name 
Csharp :: c# how to simulate mouse click 
Csharp :: enum loop 
Csharp :: c# open file dialog 
Csharp :: how to do a foreach loop in c# for dictionary 
Csharp :: unity textmeshpro 
Csharp :: how to flip character in unity 2d 
Csharp :: unity why is there no transform.left 
Csharp :: c# set a guid 
Csharp :: how to make a method wait in unity 
Csharp :: c# list string initialize inline 
Csharp :: unity add explosion force 
Csharp :: how to find the mouse position unity 
Csharp :: random value in array c# 
Csharp :: unity print 
Csharp :: how to do cmd command c# 
Csharp :: radians to degree c# 
Csharp :: shaking camera in c# 
Csharp :: OnCollision update 
Csharp :: c# count specific element in list 
Csharp :: unity move character 
Csharp :: dynamics 365 update record c# 
Csharp :: dyncmics 365 setstate request 
Csharp :: xamarin picker item 
Csharp :: How To Get The Global Position of a GameObject in a Variable 
Csharp :: reference to another script unity 
Csharp :: asp.net throw unauthorized exception 
Csharp :: how to convert a number to 2 decimal places in c# 
Csharp :: c# const string array 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =