CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
* Ricorsively sum of an integer array
*/
#include <iostream>
using namespace std;
int main() {
int a[]={10, 8, 6, 4, 2};
int t=0;
for(int i=0;i<5;i++) {
int s=0;
for(int j=0;j<5-i;j++) {
if (j>0) cout<<"+";
cout<<a[j];
s+=a[j];
}
cout<<"="<<s<<endl;
t+=s;
}
cout<<"total:"<<t<<endl;
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run