Thursday, 20 October 2016

Write a java Program To find Factorial Of A Number

import java.util.Scanner;
class Factorial
{
 public static void main(String args[])
 {
   int n,c,fact=1;
   System.out.println("Enter the number");
   Scanner in=new Scanner(System.in);
   n=in.nextInt();
   if(n<0)
   System.out.println("Enter positive number");
   else
   {
      for(c=1;c<=n;c++)
      fact=fact*c;
      System.out.println("Factorial of" +n+ "is="+fact);
    }
 }

No comments:

Post a Comment