第十二周上机项目1 阅读程序(3)

来源:互联网 发布:java多线程程序 编辑:程序博客网 时间:2024/05/17 09:26
问题及代码:/ *                                        *Copyright  (c)  2014,烟台大学计算机学院   *All rights reserved .                        *文件名称:test .cpp                       *作    者:曹莉萍                        *完成日期:2014 年11月13日             *版 本 号:v1.0                           *                                        *问题描述:含有递归函数的程序                            *输入描述:                              *程序输出:                              * /          #include <iostream>using namespace std;void f(int);int main(){    int i=1234;    f(i);    return 0;}void f(int n){    if (n==0)        return;    else    {        f(n/10);        cout<<n%10;        return;    }}
运行结果
</pre><p><img src="http://img.blog.csdn.net/20141113203732467" alt="" /></p><p></p><p><pre name="code" class="cpp">问题及代码:/ *                                        *Copyright  (c)  2014,烟台大学计算机学院   *All rights reserved .                        *文件名称:test .cpp                       *作    者:曹莉萍                        *完成日期:2014 年11月13日             *版 本 号:v1.0                           *                                        *问题描述:含有递归函数的程序                              *输入描述:                              *程序输出:                              * /          #include <iostream>using namespace std;int sub(int);int main(){    int i=5;    cout<<sub(i)<<endl;    return 0;}int sub(int n){    int a;    if (n==1)        return 1;    a=n+sub(n-1);    return a;}

运行结果


0 0
原创粉丝点击