初C,碰到两个疑惑的地方。达人咯~~~~
编译器:Dev++
C/C++ code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int n1(int x)
{
printf("in the n(1) is: %d\n",x);
if(x <= 1) return x;
return x * n1(--x);
}
int n2(int x)
{
printf("in the n(2) is: %d\n",x);
if(x <= 1) return x;
return x * n2(x - 1);
}
int main()
{
int r1 = n1(7);
printf("The r1 Value is: %d\n",r1);
printf("\n");
int r2 = n2(7);
printf("The r2 Value is: %d\n",r2);
getch();
/*system("pause");*/
}
为什么 n1 会少第一个乘?
n1是:1 * 2 * 3 * 4 * 5 * 6
而n2是 1 * 2 * 3 * 4 * 5 * 6 * 7。
C/C++ code:
return x * n1(--x);
return x * n2(x - 1);
有区别啊?
当把 n1 的 返回值改为:
C/C++ code:
return (x--) * n1(x);
当把 n1 的 返回值改为:
C/C++ code:
return (x--) * n1(x);
<
相关问答:
13个人围成一圈,从第一个人开始顺序报号1,2,3。凡报到3者退出圈子,找出最后留在圈子中的人原来的序号
结果应该是13 可我的程序的结果是11 希望好心人帮改一下
#include <stdio.h>
#include < ......
C\C++如何计算函数的导数,本人新手,想写个程序,但是不知道如何下手,还望高手指点一二,谢过。
这个……
跟函数的具体形式有关吧,难道你想编出个“万能”的求导函数?
俺上学时想过自动推导公式,后来 ......
用这本书入门怎么样呢 跟谭浩强的相比如何? 谢谢
我把这本看了几篇,确实很好的书。就不要拿它跟 谭 的书比了, 谭 的书要照顾全国读者。
不可同日而语
一个是国外的,一个是国内的
学完c primer ......
//C 接口
extern "C"
{
TESSDLL_API int __cdecl GetTessText(const char *imagefile, char *text);
}
//我在C#中声明
//调用C DLL 中的函数
[DllImport("OCRapi.dll&quo ......
/* Note:Your choice is C IDE
作用: 随机数加密法,,,,
以下有许多不懂,请教一下,请主意代码;
*/
#include <stdio.h>
#include <stdlib.h>
union
{
int value;
struct
{
c ......