求解
编写程序,要求算出一个正整数的阶层,
#include <stdio.h> long int fac(int inum); /*the main function*/ int main(void) { int inum, iresult; printf("Please input a number, and if you want exit, input -1:\n"); while (scanf("%d", &inum), inum!=-1) { iresult=fac(inum); printf("%d's factorial is %ld\n", inum, iresult); } return 0; } /*Count the factorial of inum*/ long int fac(int inum) { long int iresult=1; while (inum>0) { iresult*=inum; inum--; } return iresult; }