#include<stdio.h>
#include<stdlib.h>
main()
{
int a,b,c;
printf("a= ");
scanf("%d",&a);
printf("b= ");
scanf("%d",&b);
if (a%b==0)
c=b;
else
do{
c=a%b;}
while(a%c!=0);
printf(" Le pgdc de %d et %d est %d \n ",a,b,c);
system("pause");
return 0;
}
2 eme méthode avec fonction
#include<stdio.h>
#include<stdlib.h>
int pgdc(int a,int b)
{
if (a%b==0)
return b;
else
return pgdc(a,a%b);
}
main()
{
int a,b;
printf("a= ");
scanf("%d",&a);
printf("b= ");
scanf("%d",&b);
printf(" Le pgdc de %d et %d est %d \n ",a,b,pgdc(a,b));
system("pause");
return 0;
}
#include<stdlib.h>
main()
{
int a,b,c;
printf("a= ");
scanf("%d",&a);
printf("b= ");
scanf("%d",&b);
if (a%b==0)
c=b;
else
do{
c=a%b;}
while(a%c!=0);
printf(" Le pgdc de %d et %d est %d \n ",a,b,c);
system("pause");
return 0;
}
2 eme méthode avec fonction
#include<stdio.h>
#include<stdlib.h>
int pgdc(int a,int b)
{
if (a%b==0)
return b;
else
return pgdc(a,a%b);
}
main()
{
int a,b;
printf("a= ");
scanf("%d",&a);
printf("b= ");
scanf("%d",&b);
printf(" Le pgdc de %d et %d est %d \n ",a,b,pgdc(a,b));
system("pause");
return 0;
}