How to print 1 to 100 without any looping using C#

后端 未结 28 1468
天命终不由人
天命终不由人 2020-12-22 19:30

I am trying to print numbers from 1 to 100 without using loops, using C#. Any clues?

28条回答
  •  借酒劲吻你
    2020-12-22 20:00

    Console.WriteLine('1');
    Console.WriteLine('2');
    ...
    Console.WriteLine('100');
    

    ...Or would you have accepted a recursive solution?

    EDIT: or you could do this and use a variable:

    int x = 1;
    Console.WriteLine(x);
    x+=1;
    Console.WriteLine('2');
    x+=1;
    ...
    x+=1
    Console.WriteLine('100');
    

提交回复
热议问题