1、栈
#include <stdio.h>
#define MAX_C 20
typedef struct stack{
int pos;
int data[20];
}Stack;
Stack st;
void main()
{
int i,n;
long res = 1;
st.pos = 0;
scanf("%d", &n);
if(n > MAX_C) return;
//push
for(i=2; i<=n; ++i)
{
st.data[st.pos++] = i;
}
//pop
while(st.pos > 0)
{
res *= st.data[--st.pos];
}
printf("%d! = %d /n", n, res);
}
2、递归
#include<stdio.h>
int fact(int n)
{
if(n==1)
{
return 1;
}
return fact(n-1)*n;
}
int main()
{
printf("%d/n",face(12));
return 0;
}