+ 1
I made a program to calculate factorial of the given number.
But when I enter 20 or greater, it shows negative value . Please tell me where I am missing. This is the code... (The main code) int factorial = 1; Console.Write("Enter the no. : "); int num = Convert.ToInt32(Console.ReadLine()); for(int x=1;x<=num;x++){ factorial *= x; } Console.WriteLine(
quot;The factorial of {num} is {factorial}"); Please help.2 Answers
+ 2
integer is not big enough, so this overflow.
Make it a double or a long or even bigger data type.
https://stackoverflow.com/questions/19230573/cannot-calculate-factorials-bigger-than-20-how-to-do-so
0
Thanks buddy