Advertisement
Istanvir389

Easiest GCD ever

Nov 19th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. int main()
  4. {
  5.     int n1, n2;
  6.  
  7.     printf("Enter two positive integers: ");
  8.     scanf("%d %d",&n1,&n2);
  9.  
  10.     while(n1!=n2)
  11.     {
  12.         if(n1 > n2)
  13.             n1 -= n2;
  14.         else
  15.             n2 -= n1;
  16.     }
  17.     printf("GCD = %d",n1);
  18.  
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement