Advertisement
lIlIlIlIIlI

ProblemSolving_gcd_2

Sep 9th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cstdio>
  4. using namespace std;
  5.  
  6. int main(){
  7.     int a, b;
  8.     printf("enter two numbers a, b: ");
  9.     while(scanf("%d%d", &a, &b) == 2){
  10.         while (b > a){
  11.             b -= a;
  12.             while (a > b)
  13.                 a -= b;
  14.         }
  15.         while (a > b){
  16.             a -= b;
  17.             while (a > b)
  18.                 b -= a;
  19.         }
  20.        
  21.         if (a == b)
  22.             printf("gcd = %d", a);
  23.     }
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement