%用matlab编程如下:创建M文件,在命令窗口输入函数名就可以了。
sum=0;
for i=1:10,
part=1;
for j=1:i,
part=part*j;
end
fprintf('part(%d)=%d.\n',i,part)
sum=sum+part;
end
fprintf('The totle sum is %d.\n',sum)
望批判采纳!心情愉快
int main(void)
{
int i, sum;
sum = 0;
for (i = 1; i <= 10; i++)
{
sum += factorial();
}
printf("sum = %d", sum);
return 0;
}
int factorial(int i)
{
static int retval = 1;
retval *= i;
return retval;
}