online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> using namespace std; double sum_recursive(int n) { if (n <= 0) { return 0.0; } else { cout << "1/" << n << (n!=1 ? " + " : " = "); // just for debugging return (1.0 / double(n)) + sum_recursive(n-1); } } double sum_iterative(int n) { double v = 0.0; if (n <= 0) { return 0.0; } for (int i=n; i>0; --i) { v += 1.0 / double(i); cout << "1/" << i << (i!=1 ? " + " : " = "); // just for debugging } return v; } int main() { const int x = 4; cout << sum_iterative(x) << " (iterative)" << endl; cout << sum_recursive(x) << " (recursive)" << endl; return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue