-7

I need to write numbers from 0-100 on the console, like this:

0,1,2

1,2,3

2,3,4

3,4,5

etc.

I really can't seem to figure this out. Any pointers would be nice!

2 Answers2

6

It's quite easy actually, something like:

for(int i = 0; i < 100; i++) {
    Console.WriteLine(string.Format("{0},{1},{2}", i, i+1, i+2));
}

It will goes from 0 to 101 because it always prints 3 numbers so the last iteration would be 99,100 otherwise. If you want it that way just edit i < 100 with i < 99.

ALFA
  • 1,726
  • 1
  • 10
  • 19
2

A LINQ way of achieving it:

Enumerable.Range(2, 99).ToList()
        .ForEach(x => Console.WriteLine($"{x - 2},{x - 1},{x}"));
Matt.G
  • 3,586
  • 2
  • 10
  • 23