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); 
    }
}

No comments:

Post a Comment

if you have any doubts, Please let me know.
Your Truly
Shashank Porwal

 jhvghvgk ;nkjn ,nkjhj