输出1到n的阶乘,用了函数,怎么都出不来正确的
#include <stdio.h>#include <stdlib.h>
#include <math.h>
/*run this program using the console pauser or add your own getch, system("pause") or input loop */
double fact(int n);
int main(int argc, char *argv[]) {
int i,n,result;
printf("enter n=");
scanf("%d",&n);
for(i=1;i<=n;i++){
result=fact(n);
printf("%d\t",result);}
getch();
return 0;
}
double fact(int n)
{int fact=1,a,i;
for(i=1;i<=n;i++){
for(a=0;a<=i;a++)
fact=fact*a;
return fact;
}}