第四周项目14-递归法求n的阶乘

来源:互联网 发布:golang 延时函数 编辑:程序博客网 时间:2024/04/30 09:22

问题及代码:

/**Copyright (c) 2015,烟台大学计算机学院*All rights reserved.*文件名称:text.cpp*作者:徐健*完成日期:2015年3月22日*版本号:v1.0**问题描述:递归求n的阶乘*输入描述:输入一个整数*程序输出:输出n的阶乘结果*/#include<ctime>#include<cstdlib>#include<iostream>using namespace std;int jiecheng(int x);int main(){    int n,m;    cin>>n;    m=jiecheng(n);    cout<<m;  return 0;}int jiecheng(int x){    if(x==1)        return 1;    else        return jiecheng(x-1)*x;}
运行结果:


知识点总结:

运用了递归来求解n的阶乘。

学习心得:

对于递归的用法有了更深一层的理解,但是运用的还不是很熟练,仍然需要大量的实践练习。

0 0