Advertisement
luizaspan

Greatest common divisor

May 13th, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. // achar máximo divisor comum entre dois números
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void)
  6. {
  7.   int a,b,i,mdc,x,y;
  8.  
  9.   printf("a= ");
  10.   scanf("%d",&a);
  11.  
  12.   printf("b= ");
  13.   scanf("%d",&b);
  14.  
  15.   for (i=1;i<=1000;++i)
  16.     {
  17.      
  18.       x=a%i;
  19.       y=b%i;
  20.       if (x==0 && y==0)
  21.     mdc=i;
  22.  
  23.     }
  24.  
  25.   printf("\nO máximo divisor comum entre %d e %d é %d.\n\n",a,b,mdc);
  26.  
  27.   return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement