progamerz Posted October 26, 2017 Share Posted October 26, 2017 Q- Write a program and ask the user to enter a number. Compute the factorial of the number and print it on the console. For example, if the user enters 5, the program should calculate 5 x 4 x 3 x 2 x 1 and display it as 5 ! = 120. Can someone help me in this? @The Hero of Time maybe? Link to comment Share on other sites More sharing options...
Shaft Posted October 26, 2017 Share Posted October 26, 2017 (edited) int numberIn = Convert.ToInt32(Console.ReadLine()); int result = 1; for(int i = numberIn; i > 0; i--;){ result = result * i; } Console.WriteLine(numberIn + "!=" + result); That should work i think. Edited October 26, 2017 by Shaft 1 Link to comment Share on other sites More sharing options...
progamerz Posted October 26, 2017 Author Share Posted October 26, 2017 14 minutes ago, Shaft said: int numberIn = Convert.ToInt32(Console.ReadLine()); int result = 1; for(int i = numberIn; i > 0; i--;){ result = result * i; } Console.WriteLine(numberIn + "!=" + result); That should work i think. Thanks appreciate it i didn't understand the question thats why Solution found, Request close Link to comment Share on other sites More sharing options...
Explv Posted October 26, 2017 Share Posted October 26, 2017 (edited) 1 hour ago, progamerz said: Q- Write a program and ask the user to enter a number. Compute the factorial of the number and print it on the console. For example, if the user enters 5, the program should calculate 5 x 4 x 3 x 2 x 1 and display it as 5 ! = 120. Can someone help me in this? @The Hero of Time maybe? You could have Googled that and found a million examples, it's an extremely common question. Either way you should have been able to figure it out, especially if you're scripter Juan. Idk how you could not understand that question, it's a fookin for loop bro. Time to start expanding your brain fam. Although the for loop method is preferred, it can also be done recursively: int Factorial(int i) { if (i <= 1) return 1; return i * Factorial(i - 1); } Edited October 26, 2017 by Explv Link to comment Share on other sites More sharing options...
progamerz Posted October 26, 2017 Author Share Posted October 26, 2017 2 minutes ago, Explv said: You could have Googled that and found a million examples, it's an extremely common question. Either way you should have been able to figure it out, especially if you're scripter Juan. Idk how you could not understand that question, it's a fookin for loop bro. Time to start expanding your brain fam the factorial didn't make sense for me lol, unless i knew the question wanted like if i entered 10, it will multiply it with all number less than 10 lol Link to comment Share on other sites More sharing options...
Prolax Posted October 26, 2017 Share Posted October 26, 2017 Just an easy for loop.. 1 Link to comment Share on other sites More sharing options...
Shaft Posted October 26, 2017 Share Posted October 26, 2017 (edited) Considering you're a scripter you and u stating the equation in the question you really should have known how to do it... Also your welcome. Edited October 26, 2017 by Shaft Link to comment Share on other sites More sharing options...
progamerz Posted October 26, 2017 Author Share Posted October 26, 2017 13 minutes ago, Shaft said: Considering you're a scripter you and u stating the equation in the question you really should have known how to do it... Also your welcome. 17 minutes ago, Prolax said: Just an easy for loop.. If i am "scripter" doesn't mean i am an expert in math, i have done already 4 exercices before this using "for" loop lol Link to comment Share on other sites More sharing options...
TheWind Posted October 26, 2017 Share Posted October 26, 2017 3 minutes ago, progamerz said: If i am "scripter" doesn't mean i am an expert in math, i have done already 4 exercices before this using "for" loop lol Should look up what your trying to solve before asking for help 1 Link to comment Share on other sites More sharing options...
Tom Posted October 26, 2017 Share Posted October 26, 2017 Coulda just googled how to do it on any programming language and you would be able to convert it 2 Link to comment Share on other sites More sharing options...
progamerz Posted October 26, 2017 Author Share Posted October 26, 2017 Any more before closing ? Link to comment Share on other sites More sharing options...