Write a program to find the factorial of an integer number.
Answers
Factorial program in C programming language: Three methods to find factorial, using a for loop, using recursion and by creating a function. Factorial is represented using '!', so five factorial will be written as (5!), n factorial as (n!). Also, n! = n*(n-1)*(n-2)*(n-3)...3.2.1 and zero factorial is defined as one i.e., 0! = 1.
Factorial program
Factorial means 1st to understood ,then we see coding of it.
Factorial of number means it multuplication from 1 to that number .Factorial is represented by ! .
For ex- 5 !
5*4*3*2*1= 120 ,we cannot include 0 because then results become 0.
import java.util.*;
class Factorial
{
public static void main (String args[])
{
Scanner sc=new Scanner(System.in);
int n,i,fact=1;
System.out.println("Enter your number to find factorial");
n=sc.nextInt();
for(i=1;i<=n;i++) // you can also use it i=n;i>0;i--
{
fact*=i; // it means fact =fact*i;
}
System.out.println("Factorial of number"+n +" is " + fact);
}
}