C Program to Check Co-Prime Numbers
Two numbers are said to be co-prime numbers if they do not have a common factor other than 1 or two numbers whose Highest Common Factor (HCF) or Greatest Common Divisor (GCD) is 1 are known as co-prime numbers.
Examples of co-prime numbers are: 3 and 7 are co-prime, 7 and 10 are co-prime etc.
Note : Co-prime numbers do not require to be prime numbers.
Program
#include<stdio.h>
#include<conio.h>
int main()
{
int num1, num2, hcf, i;
clrscr();
printf("Enter two numbers:\n");
scanf("%d%d", &num1, &num2);
// Finding HCF
for(i=1;i<=num1;i++)
{
if(num1%i==0 && num2%i==0)
{
hcf = i;
}
}
// Making Decision
if(hcf == 1)
{
printf("%d and %d are CO-PRIME NUMBERS.", num1, num2);
}
else
{
printf("%d and %d are NOT CO-PRIME NUMBERS.", num1, num2);
}
getch();
return(0);
}
Output of the above program :
Run 1: ------- Enter two numbers: 13 ↲ 10 ↲ 13 and 10 are CO-PRIME NUMBERS. Run 2: ------- Enter two numbers: 15 ↲ 10 ↲ 15 and 10 are NOT CO-PRIME NUMBERS. Note: ↲ indicates enter is pressed.