Saturday, 16 May 2015

Factorial Of A Number

In this program we will find factorial of 5(which means 5! = 5*4*3*2*1 and the result will be 120).

package in.blogspot.java2bigdata
public class Factorial
{
public static void main(String args[])
{
int number = 5;
int fact = a;
for(int i=a-1;i>=1;i--)
fact = fact * i;
System.out.println("Factorial : "+ fact);
}
}

/********** OUTPUT ***********
Factorial : 120 */
//5! = 5*4*3*2*1 = 120

No comments:

Post a Comment