Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1 GCD USING EUCLIDEAN ALGORITHM
- int euclid_gcd(int m, int n)
- {
- int temp = 0;
- if(m < n)
- {
- temp = m;
- m = n;
- n = temp;
- }
- while(n != 0)
- {
- temp = m % n;
- m = n;
- n = temp;
- }
- return m;
- }
- //2 - как не надо делать;))
- #include<iostream>
- using namespace std;
- void finder()
- {
- cout<<"Enter two numbers\n";
- cin>>a>>b;
- while(a!=b)//implementing euclidean algorith
- {
- if(a>b)
- a=a-b;//subtracting the lesser number
- else
- b=b-a;
- }
- cout<<"GCD Of two numbers is "<<a<<endl;//to print can use a or b
- }
- //3 recursive
- int gcd(int u, int v)
- {
- return (v != 0) ? gcd(v, u % v) : u;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement