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

✅ UNIT 4 — POSET, LATTICES & BOOLEAN ALGEBRA (DISCRETE MATHEMATICS)

  ✅ UNIT 4 — POSET, LATTICES & BOOLEAN ALGEBRA 1. Poset Partially Ordered Set A pair (A, ≤) where relation is: Reflexive Anti-...