C++入门经典-例4.4-循环嵌套之求n的阶乘

1:代码如下:

// 4.4.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;
long Fac(int n)
{
    if(n==0)
        return 1;
    else
        return n*Fac(n-1);
}
void main()
{
    int n ;
    long f;
    cout << "please input a number" << endl;
      cin >> n ;
    f=Fac(n);
    cout << "Result :" << f << endl;
}
View Code

运行结果:

posted @ 2017-09-14 10:23  一串字符串  阅读(881)  评论(0编辑  收藏  举报