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

后端 未结 28 1437
天命终不由人
天命终不由人 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 19:58

    This is more or less pseudo code I havent done c# in years, PS running on 1 hour of sleep so i might be wrong.

    int i = 0;
    
    public void printNum(j){       
        if(j > 100){
            break;
        } else {
            print(j);
            printNum(j + 1);
        }
    }
    public void main(){
        print(i);
        printNum(i + 1);       
    }
    

提交回复
热议问题