Divide the two given numbers by their common divisors | C ++ implementation of above approach ; print the numbers after dividing them by their common factors ; iterate from 1 to minimum of a and b ; if i is the common factor of both the numbers ; Driver code ; divide A and B by their common factors
#include <bits/stdc++.h> NEW_LINE using namespace std ; void divide ( int a , int b ) { for ( int i = 2 ; i <= min ( a , b ) ; i ++ ) { while ( a % i == 0 && b % i == 0 ) { a = a / i ; b = b / i ; } } cout << " A ▁ = ▁ " << a << " , ▁ B ▁ = ▁ " << b << endl ; } int main ( ) { int A = 10 , B = 15 ; divide ( A , B ) ; return 0 ; }