Greatest common divisor
A more elegant implementation of the gcd function:

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}


To ensure that the arguments are positive, it's easiest to use the abs(...) function.



Please also indent your code nicely to make it more readable.

And put spaces around operators. For example, instead of this:


for(int i=1;i&lt;=first_number&amp;&amp;i&lt;=second_number;i++){



Write like this:

for (int i = 1; i &lt;= first_number &amp;&amp;i &lt;= second_number; i++) {




Putting it together, the implementation of the entire program can become short and sweet:

#include &lt;iostream&gt;

using std::cin;
using std::cout;
using std::endl;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    int num1, num2;

    cout &lt;&lt; "Enter first number: ";
    cin &gt;&gt; num1;
    cout &lt;&lt; "Enter second number: ";
    cin &gt;&gt; num2;

    cout &lt;&lt; "Greatest Common Divisor: " &lt;&lt; gcd(abs(num1), abs(num2)) &lt;&lt; endl;
}


You can play with this on ideone.