#include<iostream.h>
int main()
{
int first_number,second_number,gcd,i;
cout<<"Enter First Number : ";
cin>>first_number;
cout<<"Enter Second Number: ";
cin>>second_number;
for(i=1;i<=first_number&&i<=second_number;i++)
{
if(first_number%i==0 && second_number%i == 0 )
{
gcd=i;
}
}
cout<<"Greatest Common Division (GCD):"<<gcd<<endl;
return 0;
}
What is GCD of two numbers?
It means a greatest number which divides both numbers
For example: Two numbers are 9 and 24
Numbers which divides both are 1 and 3 in which greatest number is 3
So 3 is the GCD of 9 and 24
Click here for more programs on C++
int main()
{
int first_number,second_number,gcd,i;
cout<<"Enter First Number : ";
cin>>first_number;
cout<<"Enter Second Number: ";
cin>>second_number;
for(i=1;i<=first_number&&i<=second_number;i++)
{
if(first_number%i==0 && second_number%i == 0 )
{
gcd=i;
}
}
cout<<"Greatest Common Division (GCD):"<<gcd<<endl;
return 0;
}
******Output******
Enter First Number: 9
Enter Second Number: 24
Greatest Common Division (GCD):3
What is GCD of two numbers?
It means a greatest number which divides both numbers
For example: Two numbers are 9 and 24
Numbers which divides both are 1 and 3 in which greatest number is 3
So 3 is the GCD of 9 and 24
Click here for more programs on C++
No comments:
Post a Comment