diff --git a/递归求和.cpp b/递归求和.cpp new file mode 100644 index 0000000..f73acf8 --- /dev/null +++ b/递归求和.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +int SumArray(int a[], int n, int x) { + if (n == 0) { + return 0; + } else { + return a[x - n] + SumArray(a, n - 1, x); + } +} + +int main() { + int a[50], n; + cout << "ÇëÊäÈëÊý×éÖÐÊýµÄ¸öÊý£º"; + cin >> n; + cout << "ÇëÏòÊý×éÊäÈ룺"; + + for (int i = 0; i < n; i++) { + + cin >> a[i]; + } + + cout << "Êý×éµÄºÍΪ£º" ; + cout << SumArray(a, n, n); + return 0; +} \ No newline at end of file