fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void f(int *p, int *e) {if (p<=e) {*p+=*(p-1); f(p+1,e);}}
  5. void g(int *p, int *e, int a) {if (p<=e) {int t=*p; *p=a; g(p+1,e,a+t);}}
  6. void s(int *p, int *e) {if (p<=e) {cout<<*p<<" "; s(p+1,e);} else cout<< "\n";}
  7.  
  8. int main() {
  9. const int N = 5;
  10. int a[N] = {1,2,3,4,5}, *ae=a+N-1;
  11. s(a,ae); f(a+1,ae); s(a,ae);
  12. int b[N] = {1,2,3,4,5}, *be=b+N-1;
  13. s(b,be); g(b,be,0); s(b,be);
  14. return 0;
  15. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1 2 3 4 5 
1 3 6 10 15 
1 2 3 4 5 
0 1 3 6 10