您的位置:

c语言strange,c语言strandtimenull

本文目录一览:

函数代码如下: int strange(int n) { int ans; if(n==1) ans=0; else ans=1+strange(n/2); return(ans);}

不知道你是否写错了,是一个递归函数 :

如果输入1,返回0,输入其他的数返回1

c语言统计字符个数时出现这样的错误为什么

这个应该是想取得最大单词长度的。

imax只有在读取到了空格时,才会判断然后赋值,即imax= 4 - 1 = 3

如果你输入的是:key空格strange空格 的话,imax= 8 - 1 = 7

C语言pow函数一直报错~急~是不是变量都是小数不能运算啊

有两个问题,

1. 第三个输出格式错误了!!!:printf(" 3 %%0.1f %0.3f %0.3f\n",100*a3[i],b3[i],tx3[i]);,多了一个 %,正确格式:

printf(" 3 %0.1f %0.3f %0.3f\n",100*a3[i],b3[i],tx3[i]);

2. 编译不会自动链接math的库,

gcc strange.c

/tmp/ccMYdgve.o: In function `main':

strange.c:(.text+0x87e): undefined reference to `pow'

strange.c:(.text+0x947): undefined reference to `pow'

strange.c:(.text+0xa0a): undefined reference to `pow'

strange.c:(.text+0xa9a): undefined reference to `pow'

collect2: ld returned 1 exit status

解决办法,加上 -lm 编译选项。

qunengrong@qunengrong-laptop ~/test

$gcc strange.c -lm

qunengrong@qunengrong-laptop ~/test

编译成功了,运行可得结果:

./a.out

0 100.0 100.0 100.00 1 100.0 1.061 14.142 14.142 5414.21 1.062

2 100.0 0.707 0.000

3 100.0 0.000 1.062

1 1502.5 100.0 1502.51 1 1502.5 0.071 0.941 0.941 4094.12 1.005

2 100.0 0.047 0.000

3 1502.5 -1.755 1.005

2 1420.8 100.0 1420.82 1 1420.8 0.075 0.995 0.995 4099.54 1.005

2 100.0 0.050 0.000

3 1420.8 0.000 1.005

3 1421.2 100.0 1421.23 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 -0.000 1.005

4 1421.2 100.0 1421.24 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

5 1421.2 100.0 1421.25 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 -0.000 1.005

6 1421.2 100.0 1421.26 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 -0.000 1.005

7 1421.2 100.0 1421.27 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

8 1421.2 100.0 1421.28 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

9 1421.2 100.0 1421.29 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 -0.000 1.005

10 1421.2 100.0 1421.210 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

11 1421.2 100.0 1421.211 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

12 1421.2 100.0 1421.212 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 -0.000 1.005

13 1421.2 100.0 1421.213 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 -0.000 1.005

14 1421.2 100.0 1421.214 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

15 1421.2 100.0 1421.215 1 1421.2 0.075 0.995 13073.374 53858472.00 1.000

2 100.0 0.050 1.000

3 1421.2 13073.374 1.000

16 18579631.2 1307337.4 18579631.216 1 18579631.2 0.000 0.000 0.000 4099.51 1.005

2 1307337.4 0.000 0.000

3 18579631.2 0.000 1.005

17 1421.2 100.0 1421.217 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

18 1421.2 100.0 1421.218 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

19 1421.2 100.0 1421.219 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

20 1421.2 100.0 1421.220 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

21 1421.2 100.0 1421.221 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

22 1421.2 100.0 1421.222 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

23 1421.2 100.0 1421.223 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

24 1421.2 100.0 1421.224 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

25 1421.2 100.0 1421.225 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

26 1421.2 100.0 1421.226 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

27 1421.2 100.0 1421.227 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

28 1421.2 100.0 1421.228 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

29 1421.2 100.0 1421.229 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

30 1421.2 100.0 1421.230 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

31 1421.2 100.0 1421.231 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

32 1421.2 100.0 1421.232 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

33 1421.2 100.0 1421.233 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

34 1421.2 100.0 1421.234 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

35 1421.2 100.0 1421.235 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

36 1421.2 100.0 1421.236 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

37 1421.2 100.0 1421.237 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

38 1421.2 100.0 1421.238 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

39 1421.2 100.0 1421.239 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

40 1421.2 100.0 1421.240 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

41 1421.2 100.0 1421.241 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

42 1421.2 100.0 1421.242 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

43 1421.2 100.0 1421.243 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

44 1421.2 100.0 1421.244 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

45 1421.2 100.0 1421.245 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

46 1421.2 100.0 1421.246 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

47 1421.2 100.0 1421.247 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

48 1421.2 100.0 1421.248 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

49 1421.2 100.0 1421.249 1 1421.2 0.075 0.995 0.995 4099.51 1.005

2 100.0 0.050 0.000

3 1421.2 0.000 1.005

后记: pow 函数,计算时默认对double类型进行运算,float也可以会自动转换的,小数也没问题,在linux下你可以参看原型:

$man 3 pow

SYNOPSIS

#include math.h

double pow(double x, double y);

float powf(float x, float y);

long double powl(long double x, long double y);

Link with -lm.