標(biāo)題:
c++用遞歸求和程序
[打印本頁(yè)]
作者:
51hei社區(qū)
時(shí)間:
2016-1-10 23:17
標(biāo)題:
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;
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1