如何使用C#打印1到100,没有任何循环 [英] How to print 1 to 100 without any looping using C#

查看:374
本文介绍了如何使用C#打印1到100,没有任何循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试打印从1到100的数字,而不使用循环,使用C#。任何线索?

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

推荐答案

递归可能?

public static void PrintNext(i) {
    if (i <= 100) {
        Console.Write(i + " ");
        PrintNext(i + 1);
    }
}

public static void Main() {
    PrintNext(1);
}

这篇关于如何使用C#打印1到100,没有任何循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆