diff --git a/递归求和.cpp b/递归求和.cpp new file mode 100644 index 0000000..7c802c5 --- /dev/null +++ b/递归求和.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; + +int SumArray(int a[], int n, int len) +{ + if (n == 0) //»ùÏßÌõ¼þ + { + return 0; + } + else //µÝ¹éÌõ¼þ + { + return a[len - n] + SumArray(a, n - 1, len); + } +} + +int main() +{ + int a[50], n; + cout<<"ÇëÊäÈëÊý×éÖÐÊýµÄ¸öÊý"; + cin >> n; + cout<<"ÇëÏòÊý×éÊäÈë"; + for (int i = 0; i < n; i++) + { + cin >> a[i]; + } + + cout <<"Êý×éµÄºÍΪ£º" ; + cout<