Exercice 2 gcd

#include <stdio.h>
/*
Exercice 2

Le PGCD de maniere recursirve

http://www.Software-DS.com
*/

int gcd(int x,int y);

int main(void) {
int a,b;

printf("PGCD\n");

/* Saisie */
do{
printf("\nx =");
scanf("%d",&a);
} while(a<1);
do{
printf("\ny =");
scanf("%d",&b);
} while(b<1);

/* Resultat */

printf("\nPGCD(%d,%d)= %d\n",a,b,gcd(a,b));

printf("\nhttp://www.Software-DS.com\n");
return(0);
/* ©2002 All Rights Reserved to Didier STRAUS www.Software-DS.com */
}

int gcd(int x,int y){
if (x>y)
return gcd(x-y,y);
else if (x<y)
return gcd(x,y-x);
else
return x;
}
 




Haut de la page - Page générée en 0.01500 sec.
 

1847337 visiteurs.   ©2001-2024 All Rights Reserved to Software-DS.com
Made with a mac  
Confidentialité