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 = 5;
  12. cout << "Jumlah 1 sampai " << n << " = " << jumlahDeret(n) << endl;
  13. return 0;
  14. }
Success #stdin #stdout 0s 5348KB
stdin
5
stdout
Jumlah 1 sampai 5 = 15