标题:
c++用递归求和程序
[打印本页]
作者:
51hei社区
时间:
2016-1-10 23:17
标题:
c++用递归求和程序
#ifndef WYZ_WYZ
#define WYZ_WYZ
#include<iostream>
template<typename Any>
Any Rsum(Any a[],int n)
{
if(n>0)
return Rsum(a,n-1)+a[n-1];
return 0;
/*Any tsum=0;
for(int i=0;i<n;++i)
tsum+=a[i];
return tsum;*/
}
#endif
............................................................
#include<iostream>
#include"110.h"
int main()
{
using std::cout;
using std::cin;
using std::endl;
int a[100],i=0;
while(cin>>a[i]&&i<100)
{
i++;
}
cout<<Rsum(a,i);
return 0;
}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1