利用静态变量static,输出15的阶乘值。

解:程序:

 

#include<stdio.h>


int fac(int n)

{

static int f=1;

f = f*n;

return f;

}


int main()

{

int i;

for (i = 1; i <=5; i++)

{

printf("%d!=%d\n",i,fac(i));

}

return 0;

}

结果:

1!=1

2!=2

3!=6

4!=24

5!=120

请按任意键继续. . .