Saturday, June 29, 2013

Write a program to find the given two no is co-prime or not ?

Program:
#include<stdio.h>
#include<conio.h>

void main()
{
int no1,no2,temp,temp1,temp2;
clrscr();
printf("\n enter the two no decesending order ");
scanf("%d%d",&no1,&no2);
temp1=no1;
temp2=no2;
while(no2!=0)
{
temp=no1%no2;
no1=no2;
no2=temp;
}
if(no1==1)
printf("\n the %d and %d is co-prime",temp1,temp2);
else
printf("\n the %d and %d is not co-prime",temp1,temp2);
getch();
}

Output:
image
What is co-prime ?
The 2 no which has highest common factor as 1 is called co-prime.




Like the Post? Do share with your Friends.

2 comments:

  1. Replies
    1. void main()
      {
      int i,count=0,n;
      clrscr();
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
      if(n%i==0)
      {
      count=1;
      break;
      }
      }
      if(count==0)
      printf("prime");
      else
      printf("Not prime");
      }

      Delete