输出1-100,不能用循环、goto或者递归
c语言吧
全部回复
仅看楼主
level 15
震天之虎虎🐯
楼主
刚刚居然收到这么一个邮件。。
同志们动脑筋吧!
2014年04月06日 04点04分
1
level 4
雪景最美啊
printf 1......100
2014年04月06日 04点04分
3
震天之虎虎🐯
恩,其实我也是这么想的。。
2014年04月06日 04点04分
超级挖
我也是
2014年04月06日 07点04分
震天之虎虎🐯
回复 844266203 :有Perl的话,可以用system ("perl -e 'print 1..100'");
2014年04月06日 07点04分
level 3
知非.
不能用循环,那么只能用顺序和选择来构造算法,选择好像用不上,只能顺序输出了
2014年04月06日 04点04分
4
level 1
艾滴滴网络
写一个方法。然后。你懂的
2014年04月06日 04点04分
5
level 10
凡小宝
明显就是算法,做一个循环队列,很简单就做出来了
2014年04月06日 04点04分
6
震天之虎虎🐯
求代码。。
2014年04月06日 05点04分
凡小宝
回复 顶人的大野猪 :手机,没时间
2014年04月06日 05点04分
level 15
震天之虎虎🐯
楼主
来看下这网站给的答案。。
2014年04月06日 05点04分
7
仓颉的白巧克力
什么网站
2014年04月06日 06点04分
震天之虎虎🐯
回复 仓颉的白巧克力 :
http://www.quora.com/
。想不起来到底是怎么加到它的mailing list上的。。
2014年04月06日 06点04分
仓颉的白巧克力
回复 顶人的大野猪 :倜然发现完全不懂C
2014年04月06日 06点04分
震天之虎虎🐯
回复 仓颉的白巧克力 :倜?错别字?
2014年04月06日 06点04分
level 13
love_凯deep
a调用b b调用a 每次进入函数的时候全局变量tot++然后输出tot
2014年04月06日 05点04分
8
love_凯deep
我去。。刚刚回复你就发出来了。。
2014年04月06日 05点04分
love_凯deep
我去。。刚刚回复你就发出来了。。
2014年04月06日 05点04分
level 14
顶之座__赫卡特
#include<iostream>
using std::cout;
struct fool
{
fool()
{
static int i = 1;
cout << i++ << '\t';
}
};
int main()
{
fool f[100];
return 0;
}
2014年04月06日 05点04分
9
震天之虎虎🐯
吧主V5
2014年04月06日 05点04分
anxin_1225LOCK
@顶之座__赫卡特
反应好半天才明白什么意思。。。
2014年04月06日 06点04分
风景青青小河
原来是吧主大人
2014年04月06日 06点04分
贴吧用户_0V966DA
酷毙了!
2014年04月06日 06点04分
level 14
顶之座__赫卡特
模板元编程:
#include<iostream>
using std::cout;
template<int T>
struct Baka
{
static void aho()
{
Baka<T-1>::aho();
cout << T << '\t';
}
};
template<>
struct Baka<1>
{
static void aho()
{
cout << 1 << '\t';
}
};
int main()
{
Baka<100>::aho();
return 0;
}
2014年04月06日 06点04分
11
震天之虎虎🐯
这个算递归了吧?
2014年04月06日 06点04分
仓颉的白巧克力
回复 顶人的大野猪 :为什么感觉看不懂
2014年04月06日 06点04分
顶之座__赫卡特
回复 顶人的大野猪 :编译期的计算,最后生成的是没有的。
2014年04月06日 11点04分
letrec
膜拜
2014年04月06日 17点04分
level 12
915913244
#include <stdio.h>
int test(unsigned long k)
{
printf("%d\t",(int)k);
return 0;
}
int main(void)
{
asm volatile(
"xorq %%rbx,%%rbx\n\t"
"incq %%rbx\n\t"
"1:\n\t"
"cmpq $0x65,%%rbx\n\t"
"je 0f\n\t"
"movq %%rbx,%%rdi\n\t"
"movq %0,%%rax\n\t"
"call *%%rax\n\t"
"incq %%rbx\n\t"
"jmp 1b\n\t"
"0:\n\t"::"i"(&test):"%rbx","%rax"
);
printf("\n");
return 0;
}
2014年04月06日 06点04分
12
震天之虎虎🐯
给跪了。这个还是有goto的吧,只是没在C里而已
2014年04月06日 06点04分
915913244
回复 顶人的大野猪 :那段内嵌汇编其实就是 for(int i = 1;i < 101;++i)test(i);只不过没用C语言写,题目可没说不能用内嵌汇编.....
2014年04月06日 06点04分
震天之虎虎🐯
回复 915913244 :作弊!说了用C++嘛。。
2014年04月06日 06点04分
915913244
回复 顶人的大野猪 :下面用setjmp longjmp写了一个,这可不是作弊.....
2014年04月06日 06点04分
level 3
全球微博大杂烩
printf("1-100");
2014年04月06日 06点04分
14
震天之虎虎🐯
printf("1 to 100");面试的话你绝对赢了。。
2014年04月06日 06点04分
level 10
展臂_飞翔
只会C,C++看不懂!
2014年04月06日 06点04分
15
level 12
915913244
#include <setjmp.h>
#include <stdio.h>
int main(void)
{
jmp_buf buffer;
int i = setjmp(buffer);
if(i != 0)
printf("%d\t",i);
if(i < 100)
longjmp(buffer,i + 1);
printf("\n");
return 0;
}
这次不是作弊了吧.....
2014年04月06日 06点04分
16
震天之虎虎🐯
setjmp不算goto的一种吗?
2014年04月06日 06点04分
震天之虎虎🐯
顿时有种C都没学明白的赶脚。。
2014年04月06日 06点04分
915913244
回复 顶人的大野猪 :goto不能跨函数,不能有返回值[暂且这么称呼.... 就是int i = setjmp(buffer); 中的那个i,对应longjmp(buffer,i + 1);中的i + 1]
2014年04月06日 06点04分
915913244
回复 顶人的大野猪 :setjmp longjmp什么的用的比较少的,所以不知道也正常,设计出来是为了和C++中的throw,try,catch一样跨函数处理异常....
2014年04月06日 06点04分
level 15
震天之虎虎🐯
楼主
我来帖最佳答案吧,哈哈。。
2014年04月06日 06点04分
17
顶之座__赫卡特
Cross your fingers and hope seq exists!
2014年04月06日 07点04分
915913244
seq 1 100 | awk '{printf $0 "\t"}';echo 这样好看...
2014年04月06日 07点04分
震天之虎虎🐯
回复 915913244 :好评!
2014年04月06日 07点04分
level 15
震天之虎虎🐯
楼主
void**这种咱从来都不懂。。
2014年04月06日 07点04分
18
_永不_止步
这个看来看去想不通,楼主能指点一下嘛?
2014年04月06日 16点04分
震天之虎虎🐯
回复 _永不_止步 :这个应该算是用了递归吧,不符合要求
2014年04月06日 16点04分
_永不_止步
回复 顶人的大野猪 :这么说,这里大部分不是在递归就是在循环了
。说正事,那个 减一怎么回事,求解
2014年04月06日 16点04分
震天之虎虎🐯
回复 _永不_止步 :是啊,所以这个问题才有趣嘛。。我觉得这段代码是有问题的。我也不是很懂
2014年04月06日 16点04分
level 15
震天之虎虎🐯
楼主
这个用的是fork,但不能保证顺序。所以差评!
2014年04月06日 07点04分
19
915913244
又想出来了一个,用execve也可以.... 我去写
2014年04月06日 07点04分
level 15
震天之虎虎🐯
楼主
用这个我还不如用10L那个。。
2014年04月06日 07点04分
20
level 15
震天之虎虎🐯
楼主
2014年04月06日 07点04分
21
level 15
震天之虎虎🐯
楼主
这个跟吧主给的一样了
2014年04月06日 07点04分
22
1
2
3
尾页