Output code from 1 to n when c# n value is entered

Asked 2 years ago, Updated 2 years ago, 37 views

C.Lynn's been speaking C# for 2 weeks. I'm listening to the company lecture. Instead of solving examples and giving assignments, I'm giving assignments and listening to explanations.

Even if I search the Internet, there are not many examples of c#, so I want to get help from masters.

c#

2022-09-22 18:36

2 Answers

You have to do your homework on your own to make the class meaningful.

https://ko.wikibooks.org/wiki/%EB%B3%84_%EC%B0%8D%EA%B8%B0#C#

Please check this example.


2022-09-22 18:36

linq to try it. Just the way.

void Main()
{
    int n = 5;

    var r = from i in Enumerable.Range(1, n)
            select string.Concat(Enumerable.Repeat("*", i));

    foreach (var line in r) Console.WriteLine(line);
    Console.WriteLine();


    var r2 = from i in Enumerable.Range(1, n).Reverse()
             select string.Concat(Enumerable.Repeat("*", i));

    foreach (var line in r2) Console.WriteLine(line);
    Console.WriteLine();

    var r3 = from i in Enumerable.Range(1, n).Concat(Enumerable.Range(1, n - 1).Reverse())
             select string.Concat(Enumerable.Repeat("*", i));

    foreach (var line in r3) Console.WriteLine(line);
    Console.WriteLine();

    var r4 = from i in Enumerable.Range(1, n)
             select string.Concat(Enumerable.Range(1, i));

    foreach (var line in r4) Console.WriteLine(line);
}


*
**
***
****
*****

*****
****
***
**
*

*
**
***
****
*****
****
***
**
*

1
12
123
1234
12345


2022-09-22 18:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.