先初始化,在循环以前.#include "stdio.h"void main(){int i=1,n,sum=1; printf("请输入一个数:");scanf("%d",&n); while(i<=n){ sum=i*sum; i++;}printf("%d",sum);}另外必须有使程序循环的计数器,否则相当于死循环.