Created
August 8, 2018 15:05
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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