Tuesday, April 6, 2021

18.15. Write a function that gets two positive returns GCD (greatest common divisor).

#include<stdio.h>
#include<conio.h>
int GCD(int a, int b)
{
int c=0;

while(a%b!=0)
{
c=a%b;
a=b;
b=c;
}
return b;
}
void main ()
{
int a,b;
clrscr();
printf("Enter any positive integer: ");
scanf ("%d", &a);
printf("Enter any positive integer: ");
scanf ("%d", &b);
printf("
GCD of %d=%d", GCD(a,b)) ;
getch ();
}

No comments:

Post a Comment