Showing posts with label factorial of a number. Show all posts
Showing posts with label factorial of a number. Show all posts

Sunday, June 21, 2020

Write a program to print the Factorial of a number? (5! = 5*4*3*2*1=120)

27)   Write a program to print the Factorial of a number? (5! = 5*4*3*2*1=120)

import java.util.*;
public class Factorial
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int s =1;
        for(int i =1;i<=a;i++)
        {
            s=s*i;
        }
        System.out.println("Factorial of "+a+" = "+s); 
    }
}

 jhvghvgk ;nkjn ,nkjhj