Created
June 25, 2019 14:53
-
-
Save sheetal369/22fe8640e9b8e5fba4753c453eaff0ce to your computer and use it in GitHub Desktop.
Online Compiler : https://onlinegdb.com/H1J8Sn1gH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int rem, quot ; | |
| int hcf (int, int) ; | |
| int main() | |
| { | |
| cout << "Input two numbers : "; | |
| int a, b, num1, num2, hcf_num ; | |
| /* cin >> a, b ; //USING COMMA IS A SYNTAX ERROR */ | |
| cin >> a >> b; | |
| //for assigning max value to num1 and min value to num2 | |
| if (a>b) | |
| { | |
| num1 = a; | |
| num2 = b; | |
| } | |
| else { | |
| num1 = b; | |
| num2 = a; | |
| } | |
| hcf_num = hcf(num1, num2) ; | |
| cout << "\nUsing EUCLIDEAN Algorithm \nGreatest Common Divisor (GCD) is : "<<hcf_num ; | |
| cout << endl; | |
| return 0; | |
| } | |
| int i = 0 ; | |
| int hcf(int c, int d) | |
| { int e, f; | |
| static int num1[50], num2[50], quot[50], rem[50] ; | |
| num1[i] = c; | |
| num2[i] = d ; | |
| quot[i] = num1[i]/num2[i]; | |
| rem[i] = num1[i]%num2[i]; | |
| e = rem[i]; | |
| f = num2[i] ; | |
| if (e != 0) | |
| { | |
| i ++ ; | |
| hcf(f, e); //Using function RECURSIVELY [You can use looping instead] | |
| } | |
| else { | |
| cout << "\n------Process-------\n" ; | |
| int j ; | |
| for (j = 0 ; j<=i; j++) | |
| { | |
| cout <<num1[j] << " = "<< num2[j] << " * " << quot[j] << " + "<< rem[j] << endl; | |
| } | |
| return f; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment