rajeevs1992

GCD

Jul 12th, 2011
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include<stdio.h>
  2. void gcd(int,int);
  3.  
  4. void main()
  5. {
  6.     int a,b;
  7.     printf("\nEnter the nos ");
  8.     scanf("%d%d",&a,&b);
  9.    gcd(a,b);
  10. }
  11.  
  12. void gcd(int large,int small)
  13. {
  14.     int rem=0;
  15.     if(large>small)
  16.         rem=large%small;
  17.     else if(small>large)
  18.         rem=small%large;
  19.     else
  20.     rem=0;
  21.     if (rem==0)
  22.     {
  23.         if(large>small)
  24.             printf("\nGCD is %d",small);
  25.         else if(small>large)
  26.             printf("\nGCD is %d",large);
  27.         else
  28.             printf("\nGCD is %d",large);
  29.     }
  30.     else if (small>large)
  31.         gcd(large,rem);
  32.     else if(small<large)
  33.         gcd(small,rem);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment