作者AlinChang (响往西岸Bay Life)
看板C_and_CPP
标题Re: [问题] 新手发问..第二弹
时间Sat Apr 25 18:01:41 2009
感谢上次帮我看code的先进们...
最近又碰到问提了...complair 又不过..我用DEV 4.9.9.2
题目是这样的: 以回圈方式计算,利用N条线,可将平面分成最多几个区域? N >= 0;
我的解法如下:
#include <stdio.h>
#include <stdlib.h>
int cal (int key){
if (0==key){
return 1;
}else{
return cal(key+1)+key;
}
}
main(){
int x=0;
printf ("please insert a NO:");
scanf ("%d", x );
printf ("%d", cal(x));
system ("pause");
}
--
█ ▅ ╳╳╳╳╳╳╳ §释宪 649╳╳╳ █
█ ▉ ▉ ╳◤ ╳ 赌神 ╳╳╳ █
█ ▄ ▂◥ ▋▂ ▇ ◥ ▉ ▎╳ 怖告栏 ╳ 连个 按摩╳╳╳ █
█ ▄ ◤  ̄▎ ▄ ▄ ◤▊▎╳ ╳ 都没得干了╳╳╳ █
▉ ◤ ▃▋ / ▆
▉
▆ ▉ ╳ 出租 ╳ ●●- ◢╳╳╳ █
▉ ▎ ◤ ▅▅▅ ▎ ▉ ╳ ◢╳╳by:Alin Chang╳ █
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.60.127.18
1F:推 netsphere:&x? 04/25 18:16
2F:→ netsphere:还有你的递回不会停 04/25 18:17
3F:→ AlinChang:sorry..哈哈.。我犯了一样的错 ...>< & 唉C..有点烦 04/25 18:21
4F:推 VictorTom:complair?? compile?? compile不过先看error/warning写 04/25 18:37
5F:→ VictorTom:什麽, 看不懂英文就查字典, 看不懂中文就贴出来问.... 04/25 18:38
6F:→ VictorTom:main最好习惯 int main() 还有最後return 0什麽的.... 04/25 18:39
7F:→ VictorTom:话说, 题目要求用回圈(loop), 可是你写得是递回说 04/25 18:39
8F:→ VictorTom:(resursion)?? 题外话, 怎麽有的func是黄的有的是白的XD 04/25 18:41
9F:→ VictorTom: c 又拼错Orz PS. 小弟我还不知道这题的数学解Q_Q~ 04/25 18:43
10F:→ AlinChang:return cal(key+1)+key; 改成 // (key-1)+Key 还有 &x 04/25 18:51
11F:→ AlinChang:这样就顺利"COMPILE"了..感谢楼上更正..数学作法的话.. 04/25 18:52
12F:→ netsphere:记的数学解好像是 F(x)=F(x-1)+(x-1)可以用数学规纳法证 04/25 18:53
13F:→ AlinChang:我数学不好啦.。不过我的想法是: 0条线会有1个平面 04/25 18:53
14F:→ AlinChang:1条线会有 2 个区域;2条线最多会有 4个;3就有3+(3+1)个 04/25 18:53
15F:→ netsphere: x (?) 04/25 18:54
16F:推 snowlike:X1=2; Xn=Xn-1+N; ? 04/25 19:27
17F:→ snowlike:X0=1 修正orz 04/25 19:28
18F:→ VictorTom:我的重点不是你拼错字, 而是compile有错去看错误讯息. 04/25 22:27
19F:→ VictorTom:看不懂就贴错误讯息; 会这样问是因为, &x与x+1虽然有逻 04/25 22:28
20F:→ VictorTom:辑上的错误, 但是你贴的code我照贴到DevC++ 4.9.9.2去 04/25 22:28
21F:→ VictorTom:build是可以过的, 只是执行时一开始就会因为程式企图把 04/25 22:29
22F:→ VictorTom:使用者输入写到address 0x00去, 才产生了access 04/25 22:29
23F:→ VictorTom:violation然後程式挂掉. 所以你的问题应该是run-time 04/25 22:30
24F:→ VictorTom:error, 而不是compile time error. 04/25 22:31
25F:→ VictorTom:就算是run-time error也最好注明错误讯息, 虽然这一段 04/25 22:31
26F:→ VictorTom:code错误的地方还满容易抓的. 04/25 22:31