帮忙找下这个程序的错误!!求阶乘的,但无结果显示?谢谢!!

来源:百度知道 编辑:UC知道 时间:2024/05/26 07:40:42
#include"stdio.h"
int f(int n)
{
int t=1,j;
for(j=1;j<=n;j++)t*=j;
return t;
}
main()
{
int i;long s=0;
for(i=1;;i++)
{
s+=f(i);
if(s>680000)break;
}
printf("%ld\n",s);
getch();
}
好像还是有点问题~~算啦!!不过还是谢谢你们啦!!

你的程序已经改过来了!
cv6.0下运行通过!

#include<stdio.h>
#include<conio.h>

int f(int n)
{
int t=1, j;
for(j=1; j<=n; j++)
t*=j;
return t;
}

void main()
{
int i;
long s=0;
for(i=1; ; i++)
{
s+=f(i);
if(s>680000)
break;
}
printf("%ld\n",s);
getch();
}

诺要求一个数的阶乘,我改了一下,在下面!
#include<stdio.h>
#include<conio.h>

int f(int n)
{
int t=1, j;
for(j=1; j<=n; j++)
t*=j;
return t;
}

void main()
{
int i;
printf("\tplease input: ");
scanf("%d", &i);
printf("%ld\n",f(i));
getch();
}

要注意整数溢出!

#include"stdio.h"
int f(int n)
{
int t=1,j;
for(j