This program takes numbers from users and finds a Factorial of numbers.
factorial of a number is the multiplication of all its below number.
for example: 5! = 5*4*3*2*1 = 120
using System;
class factorial {
public static void Main() {
int i,n,fact=1;
Console.Write("Enter the number:");
n=int.Parse(Console.ReadLine());
for(i=1;i<=n;i++){
fact=fact*i;
}
Console.Write("Factorial of " +n+" is: "+fact);
}
}
Enter the number:5 Factorial of 5 is: 120
using System;
class factorial {
public int recursive_fact(int num)
{
if(num>0)
return num*recursive_fact(num-1);
else
return 1;
}
public static void Main() {
int n,ans;
Console.Write("Enter the number:");
n=int.Parse(Console.ReadLine());
factorial fact = new factorial(); // Creating Object
ans=fact.recursive_fact(n);
Console.Write("Factorial of " +n+" is: "+ans);
}
}
Enter the number:4 Factorial of 4 is: 24