#include<iostream>
using namespace std;
int Sum(int *p,int n)
{
return n==0?0:(Sum(p,n-1)+p[n-1]); //递归语句部分
}
int main()
{
int a[]={1,2,3,4,5,6,7,8,9};
int length=sizeof(a)/sizeof(a[0]);
int sum=Sum(a,length);
cout<<sum<<endl;
system("pause");
return 0;
using namespace std;
int Sum(int *p,int n)
{
return n==0?0:(Sum(p,n-1)+p[n-1]); //递归语句部分
}
int main()
{
int a[]={1,2,3,4,5,6,7,8,9};
int length=sizeof(a)/sizeof(a[0]);
int sum=Sum(a,length);
cout<<sum<<endl;
system("pause");
return 0;
}
输出结果为:45