Challenge: Method with Parameters
In this challenge you need to create a new method called factorial
which will have one parameter called n
of type int
. It should calculate the factorial of the passed value n
and output the result.
The blueprint of the program is given, fill the missing details to complete the program:
main
using System; namespace ConsoleApp { internal class Program { static void factorial(___) { if(n == 0) { Console.WriteLine(___); } else if (n > 0) { int result = 1; for (int i = 2; i <= ___; i++) { ___ } Console.WriteLine(___); } else { Console.WriteLine(___); } } static void Main(string[] args) { factorial(-1); factorial(0); factorial(5); } } }
Thanks for your feedback!