Sunday 15 June 2014

C++ program to simplify the given fraction


Here is a C++ program to simplify the given fraction. In this program just give numerator and denominator as input and the program will return simplified fraction.


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int a2,b2,grtr;
    cout<<"Enter the fraction number x and y ";
    cin>>a2>>b2;

    if(a2>b2)
        grtr=a2;
    else
        grtr=b2;
    for(int i=2;i<=grtr;i++)
    {
        while(a2%i==0&&b2%i==0)
        {
                a2/=i;
                b2/=i;
        }
    }
    cout<<"Simplified fraction = "<<a2<<"/"<<b2;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment