Greatest common divisor

  • File name: Greatest common divisor
  • Size: 1.54 KB
yes /

Download

By the Euclidean algorithm the GCF of two numbers of which the first is calculated to be greater than the second


 

#include <stdio.h>
    //Máximo común divisor de dos números mediante el algoritmo de Euclides.
    int main()
    {
        int a, b, c, r;
        printf("Maximo comun divisor de a y b\n\n");
        printf("a: ");
        scanf("%d", &a);
        printf("b: ");
        scanf("%d", &b);
        fflush(stdin);
        r=a%b;
        while(r>0)
        {
                  if (a>b){
     
     
                  a=b;
                  b=r;
                  r=a%b;
                  }else{
                       printf(" el primer numero debe ser mayor");
                       return -1;
                       }
     
        }
        printf("el maximo comun divisor es %d", b);
        getchar();
        return 0;
    }

1 vote. Average rating: 4.00 / 5.

Add a comment

You're using an AdBlock like software. Disable it to allow submit.