Large Number Factorial Program In Java - FindersAdda : Tutorials of Make Money, Computer or Internet

Monday, 20 November 2017

Large Number Factorial Program In Java




The factorial are product of every whole number from 1 to n. For example, if we want to find the factorial of 5 then 5 x 4 x 3 x 2 x 1 = 120.


Factorial is defined or represented by 5!.


In the below 2 program Q2 and Q3, we have used BigInteger class to find factorial of large number, because we can't find factorial of large number using int or long data type.

java program

BigInteger class is used for mathematical operation in java which involves very big integer calculations that are outside the limit of all available primitive data type.

BigInteger class belongs to math package.

For example if we find the factorial of 100 then it contains 158 digits output and it is not possible to store in available primitive data types. That's why we have to use BigInteger class for storing large number.


Q1. Write a program to find factorial of input number.






Output of the above program



Q2. Write a program to find factorial of the prime numbers between 50 to 100.







Output



Factorial of  53 = 4274883284060025564298013753389399649690343788366813724672000000000000
Factorial of  59 = 138683118545689835737939019720389406345902876772687432540821294940160000000000000
Factorial of  61 = 507580213877224798800856812176625227226004528988036003099405939480985600000000000000
Factorial of  67 = 36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000
Factorial of  71 = 850478588567862317521167644239926010288584608120796235886430763388588680378079017697280000000000000000
Factorial of  73 = 4470115461512684340891257138125051110076800700282905015819080092370422104067183317016903680000000000000000
Factorial of  79 = 894618213078297528685144171539831652069808216779571907213868063227837990693501860533361810841010176000000000000000000
Factorial of  83 = 39455239697206586511897471180120610571436503407643446275224357528369751562996629334879591940103770870906880000000000000000000
Factorial of  89 = 16507955160908461081216919262453619309839666236496541854913520707833171034378509739399912570787600662729080382999756800000000000000000000
Factorial of  97 = 96192759682482119853328425949563698712343813919172976158104477319333745612481875498805879175589072651261284189679678167647067832320000000000000000000000





Q3. Write a program to find factorial of a number within a given range.






Output of the above program



Read Also : Java Program To find Sum of Individual Digits of the Number.
Read Also : 2 Ways to set java path in system.
Read Also : What is literals in java?
Read Also : What is Data Types in java?


Final Words

I hope you liked this post so much. If you loved this post, Then, share with your friends and also give some suggestion that what should i improve in this post. Thank You So Much...... 

About Author

SUMIT KUMAR GUPTA
SUMIT KUMAR GUPTA

Author & Editor

Myself Sumit Kumar Gupta & 21 year's old person. I am a programmer and blogger. I spend much more time on programming and blogging and helps other programmers and bloggers.

0 comments:

Post a Comment

We are eager to see your comments.
Comment Rule :

1. Don't use any link in the comment box. If you have any problem related to link then contact me with the contact form.

2. Don't use the wrong word if you write the wrong word in comment box then it will get spam.