Program to find G.C.D and L.C.M of two numbers

Started by thiruvasagamani, Sep 22, 2008, 12:18 PM

Previous topic - Next topic

thiruvasagamani

Find G.C.D and L.C.M of two numbers

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

int gcd( int m, int n)
{
while( m!= n) // execute loop until m == n
{
if( m > n)
m= m - n; // large - small , store the results in large variable
else
n= n - m;
}
return ( m); // m or n is GCD
}

int lcm( int m, int n)
{
int gcd( int, int);
return( m * n / gcd (m , n)); // product of 2 numbers / gcd is lcm
}

main()
{
int m, n , lcm( int, int), gcd( int ,int);
printf(" enter anyu 2 values \n");
scanf("%d%d", &m,&n);
printf(" gcd is %d\n", gcd( m, n));
printf(" lcm is %d\n", lcm(m , n));
getch();
}

o/p:
If u enter m = 12 , n= 15 output gcd is 3 and output lcm is 60

NOTE 1:
gcd(12,15) = 3
gcd(12, 18) = 6
gcd(4 , 7) = 1

NOTE 2:

LCM of 12, 15 = 12 * 15 / gcd(12, 15);
Thiruvasakamani Karnan


Sam Opoka

Quote from: thiruvasagamani on Sep 22, 2008, 12:18 PM
Find G.C.D and L.C.M of two numbers

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

int gcd( int m, int n)
{
while( m!= n) // execute loop until m == n
{
if( m > n)
m= m - n; // large - small , store the results in large variable
else
n= n - m;
}
return ( m); // m or n is GCD
}

int lcm( int m, int n)
{
int gcd( int, int);
return( m * n / gcd (m , n)); // product of 2 numbers / gcd is lcm
}

main()
{
int m, n , lcm( int, int), gcd( int ,int);
printf(" enter anyu 2 values \n");
scanf("%d%d", &m,&n);
printf(" gcd is %d\n", gcd( m, n));
printf(" lcm is %d\n", lcm(m , n));
getch();
}

o/p:
If u enter m = 12 , n= 15 output gcd is 3 and output lcm is 60

NOTE 1:
gcd(12,15) = 3
gcd(12, 18) = 6
gcd(4 , 7) = 1

NOTE 2:

LCM of 12, 15 = 12 * 15 / gcd(12, 15);


Elvin-Aze

#include<iostream>
#include<cstdlib>
long a,b,m,n,c;
using namespace std;
int main()
{cin>>m>>n;
a=m;
b=n;
while(n!=0)
{
c=m%n;
m=n;
n=c;}

   
    if(m!=1)
    cout<<a/m<<" "<<b/m<<endl;
    else
    cout<<a<<" "<<b<<endl;
   
    system("pause");
    return 0;
    }
use it will udnerstand best and quickest way

grept

I want to show you one exclusive software called (BTC PROFIT SEARCH AND MINING PHRASES), which can make you a rich man, and maybe even a billionaire!
 
This program searches for Bitcoin wallets with a balance, and tries to find a secret phrase for them to get full access to the lost wallet!
 
Run the program and wait, and in order to increase your chances, install the program on all computers available to you, at work, with your friends, with your relatives, you can also ask your classmates to use the program, so your chances will increase tenfold!
Remember the more computers you use, the higher your chances of getting the treasure!
Thank me by donating if you have the opportunity.
 
Free Download:
https://t.me/btc_profit_search

grept

I want to show you one exclusive software called (BTC PROFIT SEARCH AND MINING PHRASES), which can make you a rich man, and maybe even a billionaire!
 
This program searches for Bitcoin wallets with a balance, and tries to find a secret phrase for them to get full access to the lost wallet!
 
Run the program and wait, and in order to increase your chances, install the program on all computers available to you, at work, with your friends, with your relatives, you can also ask your classmates to use the program, so your chances will increase tenfold!
Remember the more computers you use, the higher your chances of getting the treasure!
Thank me by donating if you have the opportunity.
 
Free Download:
https://t.me/btc_profit_search

grept

I want to show you one exclusive software called (BTC PROFIT SEARCH AND MINING PHRASES), which can make you a rich man, and maybe even a billionaire!
 
This program searches for Bitcoin wallets with a balance, and tries to find a secret phrase for them to get full access to the lost wallet!
 
Run the program and wait, and in order to increase your chances, install the program on all computers available to you, at work, with your friends, with your relatives, you can also ask your classmates to use the program, so your chances will increase tenfold!
Remember the more computers you use, the higher your chances of getting the treasure!
Thank me by donating if you have the opportunity.
 
Free Download:
https://t.me/btc_profit_search

grept

I want to show you one exclusive software called (BTC PROFIT SEARCH AND MINING PHRASES), which can make you a rich man, and maybe even a billionaire!
 
This program searches for Bitcoin wallets with a balance, and tries to find a secret phrase for them to get full access to the lost wallet!
 
Run the program and wait, and in order to increase your chances, install the program on all computers available to you, at work, with your friends, with your relatives, you can also ask your classmates to use the program, so your chances will increase tenfold!
Remember the more computers you use, the higher your chances of getting the treasure!
Thank me by donating if you have the opportunity.
 
Free Download:
https://t.me/btc_profit_search

grept

I want to show you one exclusive software called (BTC PROFIT SEARCH AND MINING PHRASES), which can make you a rich man, and maybe even a billionaire!
 
This program searches for Bitcoin wallets with a balance, and tries to find a secret phrase for them to get full access to the lost wallet!
 
Run the program and wait, and in order to increase your chances, install the program on all computers available to you, at work, with your friends, with your relatives, you can also ask your classmates to use the program, so your chances will increase tenfold!
Remember the more computers you use, the higher your chances of getting the treasure!
Thank me by donating if you have the opportunity.
 
Free Download:
https://t.me/btc_profit_search

grept

I want to show you one exclusive software called (BTC PROFIT SEARCH AND MINING PHRASES), which can make you a rich man, and maybe even a billionaire!
 
This program searches for Bitcoin wallets with a balance, and tries to find a secret phrase for them to get full access to the lost wallet!
 
Run the program and wait, and in order to increase your chances, install the program on all computers available to you, at work, with your friends, with your relatives, you can also ask your classmates to use the program, so your chances will increase tenfold!
Remember the more computers you use, the higher your chances of getting the treasure!
Thank me by donating if you have the opportunity.
 
Free Download:
https://t.me/btc_profit_search