|
发表于 2013-11-2 23:05:00
|
显示全部楼层
# include <stdio.h>
int square (int x);
int factorial (int y);
int main (void)
{
int m, n, e, f;
int a = 2;
int b = 3;
m = square (a);
n = square (b); //程序到这一步都是对的 为嘛往下就错了 囧
e = factorial (m); //这里我单步调试为什么是垃圾值
f = factorial (n);
//printf("%d\n",e);
//printf("%d\n",f);
printf("%d\n", e + f); //为什么是零
return 0;
}
int square (int x)
{
int z;
z = x * x;
return z;
}
int factorial (int y)
{
int i;
int q = 1;
for(i = 0; i < y; ++i)//这里不能等于,否则最后y=i,结果必然为0
q = q * (y - i);
return q;
}
我改了一下,现在正确了,你注意一下我改的地方:lol: |
|