Skip to content

Instantly share code, notes, and snippets.

@wekonu
Created August 19, 2021 05:33
Show Gist options
  • Select an option

  • Save wekonu/5695e56ae78dca3d4b3b6fc1ad9ca418 to your computer and use it in GitHub Desktop.

Select an option

Save wekonu/5695e56ae78dca3d4b3b6fc1ad9ca418 to your computer and use it in GitHub Desktop.
HackerRank Day 9 - C# "Recursion 3"
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 < 2)
return 1;
return n * factorial(n - 1);
}
}
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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment