fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int jumlahDeret (int n) {
  5. if (n == 1)
  6. return 1;
  7. return n + jumlahDeret (n-1);
  8. }
  9.  
  10. int main () {
  11. int n = 7;
  12. cout << "Jumlah 1 sampai " << n << " = " << jumlahDeret (n) << endl;
  13. return 0;
  14. }
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
stdout
Jumlah 1 sampai 7 = 28