第四周项目五 用递归求n的阶乘

来源:互联网 发布:手机桌面软件管理 编辑:程序博客网 时间:2024/04/30 14:35
/*copyright(c)2016.烟台大学计算机学院* All rights reserved,* 文件名称:my dream,Cpp* 作者:舒文超* 完成日期:2016年3月20日* 版本号:vc++6.0* 问题描述:           编写递归函数求出n的阶乘  样例输入:            3  样例输出:            6*/#include<iostream>using namespace std;int main(){    int di(int x);    int n,j;    cin>>n;    j=di(n);    cout<<n<<"的阶乘为:"<<j;    return 0;}int di(int x){    if(x==0||x==1)        return 1;    else        return x*di(x-1);}

0 0
原创粉丝点击