Tuesday, February 27, 2024

Factorial in java

import java.util.*;

public class fact

{

public static void main (String [] args) {

System.out.println("Enter the no:" ) ;

Scanner s=new Scanner(System.in);

int a=s.nextInt();

int fact =1;

for(int i=0; i<=a; i++) 

fact = fact*i;

}

System.out.println("factorial of" +a+ "number is"  +fact) ;

}



output - Enter the no.

5

factorial of 5 number is 120

No comments:

Post a Comment

Day three of theory of computation

 1. Non-deterministic Finite Automata (NFA)   Unlike a DFA, an NFA allows a machine to explore multiple paths simultaneously.   Definition: ...