阶层问题,输入一个数,求0到这个数的每个阶层,求到12以后的就有问题了,求指教
#include<stdio.h>#include<stdlib.h>
long fac(int);
int main() {
int y,num,i;
scanf_s("%d", &num);
for (i = 0; i <= num; i++)//从0的阶层一直循环到num
{
y = fac(i);//求出阶层返回的值
printf("%d!=%ld\n", i, y);
}
system("pause");
}
long fac(int num)//递归求阶层
{
if (num == 1 || num == 0)
return 1;
else
return num * fac(num - 1);
}