fork download
  1. #include <iostream>
  2.  
  3. int sumtorial( int value )
  4. {
  5. if ( value )
  6. {
  7. std::cout << value ;
  8.  
  9. if (value - 1)
  10. std::cout << " + " ;
  11.  
  12. value += sumtorial(value-1) ;
  13. }
  14.  
  15. return value ;
  16. }
  17.  
  18. int main()
  19. {
  20. int result = sumtorial(6) ;
  21. std::cout << " = " << result << '\n' ;
  22. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
6 + 5 + 4 + 3 + 2 + 1 = 21