audreych

12935 - Greatest Common Divisor

Jan 1st, 2021 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.31 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int GCD(int, int);
  4. int main(){
  5.     int a, b;
  6.     scanf("%d %d", &a, &b);
  7.     printf("%d\n", GCD(a, b));
  8.     return 0;
  9. }
  10.  
  11. int GCD(int a, int b){
  12.     if(b ==0) return a;
  13.     else return GCD(b, a%b);
  14. }
  15. //euclidean algorithm
  16. //basically A=BQ + R   
  17. //GCD (A, B) = GCD(B,R)
  18. //GCD (A, 0) = A
  19. //GCD (B, 0) = B
Add Comment
Please, Sign In to add comment