Recursion 3 Solution in C#
This Page Contains the Solution in C# Programming Language for the Day 9 : Recursion 3, Code Challange of the HackerRank 30 Days of Code.
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Result
{
/*
* Complete the 'factorial' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER n as parameter.
*/
public static int factorial(int n)
{
if (n == 1) return 1;
return factorial(n - 1) * n;
}
}
class Solution
{
public static void Main(string[] args)
{
TextWriter textWriter = new StreamWriter
(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int n = Convert.ToInt32(Console.ReadLine().Trim());
int result = Result.factorial(n);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
Last updated
Was this helpful?