How to calculate factorial using class in C#

2 Answers

0 votes
using System;

class Program
{
    public static int getFactorial(int n) {
		 return (n == 1 || n == 0) ? 1 : n * getFactorial(n - 1);
	}
	
    static void Main() {
		Console.WriteLine(getFactorial(6));
    }
}



/*
run:

720

*/

 



answered Sep 29, 2023 by avibootz
0 votes
using System;

class Program
{
    public int getFactorial(int n) {
		 return (n == 1 || n == 0) ? 1 : n * getFactorial(n - 1);
	}
	
    static void Main() {
		Program obj = new Program();
		
		Console.WriteLine(obj.getFactorial(6));
    }
}



/*
run:

720

*/

 



answered Sep 29, 2023 by avibootz

Related questions

2 answers 160 views
2 answers 240 views
1 answer 163 views
163 views asked Apr 9, 2014 by avibootz
1 answer 126 views
2 answers 171 views
1 answer 146 views
2 answers 210 views
...