在C ++中打印1到100,没有循环和递归
有几种不使用循环而打印数字的方法,例如使用递归函数,goto语句和在函数外部创建main()函数。
这是一个使用C++语言使用goto语句打印数字的示例,
示例
#include <bits/stdc++.h>
using namespace std;
int main() {
int count=1;
int x;
cout << "Enter the max value of x : ";
cin >> x;
PRINT:
cout << " " << count;
count++;
if(count<=x)
goto PRINT;
return 0;
}输出结果
Enter the max value of x : 1
在上面的程序中,我们使用GOTO语句打印了从1到100的数字,而没有使用循环和递归。
PRINT: cout << " " << count; count++; if(count<=x) goto PRINT;
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短