Untitled

 avatar
unknown
c_cpp
2 years ago
1.2 kB
6
Indexable
#include <iostream>
using namespace std;

void gcd ();

int main()
{
    char z;
    cout<<"THE GCD OF TWO NUMBERS IS COMPUTED BY THIS PROGRAM\n\n";
    cout<<"--------------------------------------------------\n\n";
    gcd();
    here:
    cout<<"Would you like to keep using the progam?? Y/N : ";
    cin>>z;

    switch(z){
        case 'Y':
        case 'y':
            gcd();
            goto here;
            break;
        case 'N':
        case 'n':
            cout<<"\n\nClosing the program...\n"<<endl;
            cout<<"--------------------------------------------------";
            break;
        default:
            cout<<"\nInput is Invalid!\n\n";
            cout<<"--------------------------------------------------";
            break;
    }
    return 0;
}

void gcd()
{
    int x,y,divide,remaindr;
    here:
    cout<<"Enter a number: ";
    cin>>x;
    cout<<"Enter a second number: ";
    cin>>y;

    do{
        divide = x / y;
        remaindr = x % y;
        cout << x << " = " << y << " * " << divide << " + " << remaindr << endl;
        x = y;
        y = remaindr;

    }
    while(y != 0);
    cout<<"GCD = "<< x <<endl;
}
Editor is loading...