fact() demo

来源:互联网 发布:安卓开发php服务器端 编辑:程序博客网 时间:2024/06/03 11:34
#include <iostream>using namespace std;int fact(int n);void testFact();int main(){    testFact();    return 0;}int fact(int n) {    int ret = 1;    while (n)        ret *= n--;    return ret;}void testFact() {    cout << "Enter an positive integer: ";    int n;    cin >> n;    cout << "factorial of " << n << " == "         << fact(n) << endl;}

0 0