Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROGRAM TO FIND FACTORIAL OF NUMBER USING RECURSION
#1

Code:
import java.io.*;
class Factorial
{
int fact(int n)
{
if(n<=1)
  return 1;
  else
  return (n*fact(n-1));
}
}
class Newfact
{
public static void main(String args[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
  System.out.println("Enter the number");
  int i=Integer.parseInt(dis.readLine());
  Factorial f=new Factorial();
  System.out.println("Factorial is"+f.fact(i));
}
}

OUTPUT

E:\ 5BCA-B\lijo\java >javac Newfact.java
Note: Newfact.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

E:\ 5BCA-B\lijo\java >java Newfact
Enter the number
5
Factorial is 120
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.