Tuesday 16 September 2014

write a c++ program to find the GCD and LCM of two integers output the resuls along with the given integers.use Euclid's distance.

#include<iostream>
using namespace std;
int main()
{   int num1,num2;
    int m1,m2,r;
cout<<"enter two numbers"<<endl;
cin>>num1>>num2;
if(num1>num2)
{
  m1=num1;
  m2=num2;
}
else
{ m1=num2;
 m2=num1;

}
while(r!=0)
{
r=m1%m2;
m1=m2;
m2=r;
}
cout<<"result of gcd of two number is "<<m1<<endl;
int lcm= (num1*num2)/m1;
cout<<"result of lcm of two number is "<<lcm;
}

No comments:

Post a Comment

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...