Skip to content

Instantly share code, notes, and snippets.

@SergiyOsadchyy
Created August 8, 2018 15:05
Show Gist options
  • Save SergiyOsadchyy/d02ec5e92af0962377636dd9968cf917 to your computer and use it in GitHub Desktop.
Save SergiyOsadchyy/d02ec5e92af0962377636dd9968cf917 to your computer and use it in GitHub Desktop.
Method PrintNTimes takes argument n and prints numbers from 1 to n (n times). Example: "1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5"
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
PrintNTimes(5);
}
public static void PrintNTimes(int n)
{
if (n == 0)
{
return;
}
PrintNTimes(n - 1);
if (n != 1)
{
Console.Write(", ");
}
for (int i = 1; i <= n; i++)
{
Console.Write(n);
if (i != n)
{
Console.Write(", ");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment