题目:在主程序中提示输入整数n,编写函数用递归的方法求1+2+3+....+n的值。#include<iostream>using namespace std;int D(int n,int &M){M=M+n;if(n>=1) D(n-1,M);else return 0;}int main(){int n,M=0;while(cin>>n){D(n,M);cout<<"从1加到"<<n<<"的和为:"<<M<<endl;}cout<<"input error!"<<endl;} 相关文章: