using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { Console.WriteLine("Enter the Factorial Number"); int no = Convert.ToInt32( Console.ReadLine()); int x=1; for (int i = 1; i <= no; i++) { x = x * i; } Console.WriteLine("Factorial of "+ no +" = "+x); Console.ReadLine(); } } }
Recursion
static void Main(string[] args) { Console.WriteLine("Enter the Factorial Number"); int no = Convert.ToInt32( Console.ReadLine()); int x = Fac(no); Console.WriteLine("Factorial of "+ no +" = "+x); //Console.WriteLine("Factorial of "+ no +" = "+x); Console.ReadLine(); } public static int Fac(int x) { if (x == 1) { return 1; } return (x * Fac(x - 1)); }
No comments:
Post a Comment