Practicing Method with Parameters | Methods
C# Basics

Course Content

C# Basics

## C# Basics

1. Getting Started
2. Dealing with Data Types
3. Control Structures
4. Loops
5. Arrays
6. Methods

# Practicing 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

1. We had done a factorial related exercise in one of the previous sections but to recap, the factorial of a number is the product of all the numbers up till that number. For-example the factorial of `5` is `1 x 2 x 3 x 4 x 5` which is `120`, similarly the factorial of `4` is `24`. There are two additional rules:
• Factorial of `0` is `1`;
• Factorial of a negative number is `undefined` so it should output `undefined`;
1. For solving the task, following the following steps:
• Fill in the blank for the `factorial` method with appropriate parameter definition. It expects an integer. Figure out what should be the name of the parameter by reading the method's inner code;
• If the passed argument is `0`, it should show a fixed output which is mentioned in the hints;
• The loop should continue up till (including the number) the passed integer. The `result` variable should be updated with the product of itself with the loop variable. In short: `result *= i`;
• If the input number is negative (invalid), it should output "undefined".

main

Everything was clear?

Section 6. Chapter 5
We're sorry to hear that something went wrong. What happened?