Greatest Common Factor (C++)
Photo Courtesy:ekoolguru
Program for finding G.C.D b/w two Numbers
#include<iostream.h>
#include<conio.h>
void main()
/*Open Source*/
/*author @lol ik*/C
{
int c,a,b,i,j,k=1;
cout<<"Enter the 1st no.";
cin>>a;
cout<<"Enter the Second no." ;
cin>>b;
for(i=1;i<=(a/2)&&i<=(b/2);i++)
{
for(j=2;j<=i;j++)
{
if(i%j==0)
{
if(a%i==0&&b%i==0)
{
k*=i;
}
}
}
}
cout<<k;
getch();
}
Posted by lol ik
Comments
Post a Comment