不用循环,怎么输出1-100?

五号智能 2008-07-11 07:03:47
刚才在JAVA论坛里看到的帖子,

呵呵,用C++,能不能做出这东西?





...全文
856 54 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
54 条回复
切换为时间正序
请发表友善的回复…
发表回复
yumenlong5149 2011-03-07
  • 打赏
  • 举报
回复
如果再加一个条件 不用判断了?
XiaoG602 2008-07-19
  • 打赏
  • 举报
回复
递归
lunarfan 2008-07-12
  • 打赏
  • 举报
回复
if+goto 递归其实都是循环
要么就直接输出
这题没意思。
skineffect 2008-07-12
  • 打赏
  • 举报
回复
递归呗,当然最简单的就用个cout搞定。。。。
stshow 2008-07-12
  • 打赏
  • 举报
回复
寒~~~~~~~~
递归就是一种循环~~~~~~~~~~
cout<< 1


(省略号)



cout<< 100
雨过白鹭洲 2008-07-12
  • 打赏
  • 举报
回复
这种题有什么意义?
visir 2008-07-12
  • 打赏
  • 举报
回复
void print()
{
static int n= 0;
if (n == 101) return;
cout < <n++ < <endl;
print();
}
visir 2008-07-12
  • 打赏
  • 举报
回复
void print()
{
static int n= 100;
if (n) return;
cout<<n--<<endl;
print();
}
Vegertar 2008-07-12
  • 打赏
  • 举报
回复
# include <iostream>
# include <cstdlib>

bool print(int n)
{
if(n&&print(n-1))
std::cout<<n<<" ";
return 1;
}

int main()
{
print(100);

std::system("pause");
return 0;
}
qqwx_1986 2008-07-12
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;
int i=0;
class C{
public:
C()
{
cout<<++i<<" ";
}
~C()
{
cout<<++i<<" ";
}
};

void main(void)
{
C c[50];
}
jy01807853 2008-07-12
  • 打赏
  • 举报
回复
[Quote]
发表于:2008-07-12 05:50:11 42楼
cout < <'1' < <endl;
...
...
cout < <'100' < <endl;
绝对符合题意。。
[/Quote]

你这个也不对吧
你不停的写输出
难道不算是手动循环
呵呵~~~~~~~~~~
happycomputer1 2008-07-12
  • 打赏
  • 举报
回复
只能用递归了,变相的循环

int myrecyle(int temp)
{

if (temp)
{
myrecyle(temp-1);
cout<<temp<<endl;
}
else
{
return 0;
}

}
jackfeige 2008-07-12
  • 打赏
  • 举报
回复
cout<<'1'<<endl;
...
...
cout<<'100'<<endl;
绝对符合题意。。
jy01807853 2008-07-12
  • 打赏
  • 举报
回复
其实这道题,我感觉是在玩文字游戏
递归算循环吧
我感觉只要程序里面有++或者--
别人都可以说是循环
我个人的一点愚见
chinagavin 2008-07-12
  • 打赏
  • 举报
回复
递归
  • 打赏
  • 举报
回复
递归/GoTo+判断
macfan 2008-07-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 babyvox1999 的回复:]
递归
[/Quote]
自己用递归写了一个,看下其实实质还是循环,\

#include <iostream>
using namespace std;

fun(int x)
{
if (1==x)
return 1;
else
{
cout<<x<<endl;
return fun(x-1);
}
}

int main()
{
int y;
int a=100;
y=fun(a);
cout<<y;
return 0;
}
wacn 2008-07-12
  • 打赏
  • 举报
回复
void coutFrom2To(list<int>*ls,int from,int to)
{
if(from > to)
return;
ls->push_front(from);
while(!ls->emapty())
{
int topValue = ls.front();
cout << topValue;
ls.pop_front();

if(topValue != to)
{
list->push_front(topValue+1);
}
else{
return;
}

}
}
int main(){


/*test function coutFrom2To(list*,int,int)*/
coutFrom2To(new list<int>,0,100);

}
ndsl3334 2008-07-12
  • 打赏
  • 举报
回复
....
cout << "1-100" << endl;
e_sharp 2008-07-11
  • 打赏
  • 举报
回复
递归,goto

[Quote=引用 14 楼 sukyin 的回复:]
还有goto嘛。当然,这个变相也是一种循环。

yoho:
++i;
printf("%d",i);
if(i <100) goto yoho;
[/Quote]

[Quote=引用 5 楼 k2eats 的回复:]
递归是可以的

C/C++ code
#include <iostream>
using namespace std;
void print(int n)
{
if(n==1)
{
cout<<101-n<<endl;
return ;
}
cout<<101-n<<endl;
print(n-1);
}

int main()
{
print(100);
}
[/Quote]
加载更多回复(34)

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧