Rational arithmetic from given input
I see a number of things that may help you improve your code.

Use only required #includes

The code has a great number of #includes that are not needed.  Some files are even listed twice.  This clutters the code and makes it more difficult to read and understand.  Only include files that are actually needed.

Don't Repeat Yourself (DRY)

The mathematical operations all include large portions of repeated code.  Instead of repeating code, it's generally better to make common code into a function.

Don't abuse using namespace std

Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid.  

Use objects

Since you're writing in C++, what would make more sense to me would be to create a rational fraction object. Then each mathematical operation would be very naturally expressed as an operator on the object. 

Use switch instead of nested if

The more appropriate control flow for your if statement in main is a switch statement.  This makes it somewhat clearer to read and understand and often provides a small improvement in performance, especially if there are many cases.

Prefer iostream to stdio.h

Using iostream style I/O makes the code easier to adapt to change.  For example, using scanf, the code has to have the appropriate matching format string for each argument, but using the &gt;&gt; operator, there is no such requirement and the compiler adapts automatically to whatever type is being read.

Omit return 0

When a C++ program reaches the end of main the compiler will automatically generate code to return 0, so there is no reason to put return 0; explicitly at the end of main.

Putting it all together

Here's an alternative implementation which uses all of these suggestions.  Note that a rational fraction is only reduced when it is being printed.  This saves some time over always maintaining that state.

#include &lt;iostream&gt;

class RationalFraction
{
public:
    RationalFraction(long long a=0, long long b=1)
        : num{a}, den{b}
        { }
    // unary negation
    RationalFraction&amp; operator-() { num = -num; return *this; }
    // add the passed fraction to this one
    // The two-operand addition is built from this, and a 
    // similar pattern is used for each of the other operators.
    RationalFraction&amp; operator+=(const RationalFraction &amp;rh) {
        num = num * rh.den + rh.num *den;
        den *= rh.den;
        return *this;
    }
    RationalFraction&amp; operator-=(const RationalFraction &amp;rh) {
        num = num * rh.den - rh.num *den;
        den *= rh.den;
        return *this;
    }
    RationalFraction&amp; operator*=(const RationalFraction &amp;rh) {
        num *= rh.num;
        den *= rh.den;
        return *this;
    }
    RationalFraction&amp; operator/=(const RationalFraction &amp;rh) {
        num *= rh.den;
        den *= rh.num;
        return *this;
    }
    friend std::ostream &amp;operator&lt;&lt; (std::ostream&amp; out, const RationalFraction&amp; f) {
        RationalFraction fr=f;
        fr.reduce();
        return out &lt;&lt; fr.num &lt;&lt; " / " &lt;&lt; fr.den;
    }
    friend std::istream &amp;operator&gt;&gt; (std::istream&amp; in, RationalFraction&amp; f) {
        return in &gt;&gt; f.num &gt;&gt; f.den;
    }

private:
    void reduce() {
        if (num == 0) {
            den = 1;
            return;
        }
        long long mygcd = gcd(num, den);
        num /= mygcd;
        den /= mygcd;
        if (den &lt; 0) {
            den = -den;
            num = -num;
        }
    }
    long long gcd(long long a, long long b) const {
        long long  c;
        while(b != 0){
            c = a % b;
            a = b;
            b = c;
        }
        return a;
    }

    // data members
    long long num, den;
};

RationalFraction operator+(RationalFraction lh, const RationalFraction &amp;rh)
{
    lh += rh;
    return lh;
}

RationalFraction operator-(RationalFraction lh, const RationalFraction &amp;rh)
{
    lh -= rh;
    return lh;
}

RationalFraction operator*(RationalFraction lh, const RationalFraction &amp;rh)
{
    lh *= rh;
    return lh;
}

RationalFraction operator/(RationalFraction lh, const RationalFraction &amp;rh)
{
    lh /= rh;
    return lh;
}

int main()
{
    int numOp;
    for (std::cin &gt;&gt; numOp; numOp; --numOp) {
        RationalFraction lhs, rhs;
        char op[2];
        std::cin &gt;&gt; lhs &gt;&gt; op &gt;&gt; rhs;
        switch (op[0]) {
            case '+':
                std::cout &lt;&lt; lhs+rhs &lt;&lt; '\n';
                break;
            case '-':
                std::cout &lt;&lt; lhs-rhs &lt;&lt; '\n';
                break;
            case '/':
                std::cout &lt;&lt; lhs/rhs &lt;&lt; '\n';
                break;
            default:
                std::cout &lt;&lt; lhs*rhs &lt;&lt; '\n';
        }
    }
}


A bit more detail

To understand this version of the code, it's useful to look at a few individual class member functions.  First, is the constructor:

    RationalFraction(long long a=0, long long b=1)
        : num{a}, den{b}
        { }


This allows for construction in a few different ways:

RationalFraction half{1,2};   // 1/2 = one half
RationalFraction three{3};    // 3/1 = 3
RationalFraction zero;        // 0/1 = 0


The basic four mathematical functions are all built in the same way.  First, there is a member function such as +=:

    RationalFraction&amp; operator+=(const RationalFraction &amp;rh) {
        num = num * rh.den + rh.num *den;
        den *= rh.den;
        return *this;
    }


This version is a member function and can be used like this:

RationalFraction a{1,3};
RationalFraction b{1,2};  
a += b;    // now a = 5/6 and b is unchanged


It's a common idiom to define those member functions first and then construct the two-operand versions:

RationalFraction operator+(RationalFraction lh, const RationalFraction &amp;rh)
{
    lh += rh;
    return lh;
}


This is a bit subtle.  Note that lh is passed by value, so that means a local copy is constructed using the compiler-generated default copy.  By contrast rh is a const reference, so no additional copy is created.  Now all we need to do is apply the member function version and return lh which, remember, is a copy of whatever was originally passed in for that parameter.  It is a standalone function and not a member function so that either of these works:

RationalFraction f={-1,2};
std::cout &lt;&lt; f+3 &lt;&lt; std::endl;  // (-1/2) + 3 = 5/2
std::cout &lt;&lt; 3+f &lt;&lt; std::endl;  // 3 + (-1/2) = 5/2


In the expression 3+f first a temporary rational fraction is created from 3.  Then that rational fraction is added to f and the result displayed using the &lt;&lt; operator.  That is, it's approximately the equivalent to this:

RationalFraction temp1{3};   // = 3/1
RationalFraction temp2 = temp1 + f;  // do addition using non-member function
std::cout &lt;&lt; temp2 &lt;&lt; std::endl;  // show the result = 5/2


The only other slightly tricky bit of code is in private member function reduce.  Here I've added comments to make it easier to understand:

void reduce() {
    // if it's of the form 0/x, turn it into canonical 0/1
    if (num == 0) {
        den = 1;
        return;
    }
    // reduce by dividing by the greatest common divisor of 
    // numerator and denominator
    long long mygcd = gcd(num, den);
    num /= mygcd;
    den /= mygcd;
    // Only allow the numerator to be negative to simplify printing.
    // Changing sign of both numerator and denominator has no
    // mathematical effect on the value.
    if (den &lt; 0) {
        den = -den;
        num = -num;
    }
}