printf输出自定义函数的返回值,我有问题不明白
#include "stdio.h"float fact(int d);
int _tmain(int argc, _TCHAR* argv[])
{
int a,b;
scanf_s("%d", &a);
for (int c = 1; c <= a; c++){
b = fact(c);
printf("%d", b);
}
getchar();
getchar();
return 0;
}
float fact(int d){
int m, n = 1;
for (m = 1; m <= d; m++){
n = n*m;
}
return n;
}
代码是这样的,如果将:
for (int c = 1; c <= a; c++){
b = fact(c);
printf("%d", b);
}
换成:
for (int c = 1; c <= a; c++){
printf("%d", fact(c));
}
结果就全部变成0了,这是为什么?是转换时出了问题吗?