1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <stdio.h>
#include <stdlib.h>
int pgcd_ppcm(int n1,int n2,int pgcd,int ppcm);
int main(void)
{
int n1,n2,pgcd_ppcm,pgcd,ppcm,result;
printf("Entrer le nombres 1: ");
scanf("%d",&n1);
printf("Entrer le nombre 2: ");
scanf("%d",&n2);
if(n1<=0 || n2<=0)
printf("Pas de PGCD et PPCM");
else{
pgcd_ppcm(n1,n2,pgcd,ppcm);
printf("Le PGCD vaut : %d\nLe PPCM vaut : %d",pgcd,ppcm);
}
return 0;
}
int pgcd_ppcm(int n1,int n2,int pgcd,int ppcm)
{
int grand,petit,sauv,reste,quot;
grand=n1;
petit=n2;
if(grand<=petit) {
sauv=grand;
grand=petit;
petit=sauv;
}
reste=grand;
while(reste !=0){
quot=grand/petit;
reste=grand-(quot*petit);
grand=petit;
petit=reste;
reste++;
}
pgcd=grand;
ppcm=(n1*n2)/grand;
} |
Partager