c program to find pair of numbers are **relative prime (co-prime)**. Two integers are relatively prime if they share no common divisor except 1. Relative prime is also termed as co-prime. i.e gcd of both the numbers be 1.

**For example :**

15 and 13 are relatively prime.

20 and 15 are not relative prime as they share common divisor 5.

So the only thing we need to find is that whether the gcd (greatest common divisor) or hcf (highest common factor)of two number is 1 then they are termed as relatively prime.

## c program to find pair of numbers are relative prime:

#includen<stdio.h> #include<conio.h> int hcf(int a, int h) { int temp; while(1) { temp = a%h; if(temp==0) return h; a = h; h = temp; } } int main() { int c,d,gcd; printf("enter two values to find for relative prime or co prime\n"); scanf("%d%d",&c,&d); gcd=hcf(c,d); if(gcd==1) { printf("\n%d and %d are relatively prime or co prime numbers .",c,d); } else { printf("\n%d and %d are not relatively prime or co prime numbers .",c,d); } getch(); }

Output :

If you find any problem while compiling and execution of program, your comments are most welcome. We will look upon it.

very simple and nice logic. now I have understood the concept. thank you !

temp = a%h;

if (temp== 0 )

return h; a = h; h = temp;

please explain this..