C++扬帆远航——18(项目五2,递归式)

/*
 * Copyright (c) 2016,烟台大学计算机与控制工程学院
 * All rights reserved.
 * 文件名:qiushi.cpp
 * 作者:常轩
 * 微信公众号:Worldhello
 * 完成日期:2016年3月23日
 * 版本号:V1.0
 * 问题描述:求1*3*5*......*n的递归式
 * 程序输入:n
 * 程序输出:见运行结果
 */

#include<iostream>
using namespace std;
int main()
{
	int f(int );
    int n;
	cin>>n;
    cout<<f(n)<<endl;
	return 0;
}

int f(int x)
{
   if(x==1)
	   return 1;
   else
	   return (x*f(x-2));
}

运行结果:

心得:

      多练

原文地址:https://www.cnblogs.com/chxuan/p/8232264.html