Advertisement
Shailrshah

Euclid's Algorithm(Recursive) to compute GCD

Dec 2nd, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1. #include <stdio.h>
  2. int gcd(int a, int b){
  3.     if (!b) return a; //if b is less than 1, return a
  4.     else return gcd(b, a % b); // if b is positive, call the function again
  5. }
  6. int main(){
  7.     int a, b;
  8.     printf("Enter two integers: ");
  9.     scanf("%d%d", &a, &b);
  10.     printf("The GCD is %d.", gcd(a,b));
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement