News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

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

ppu-pro_Sn

Наша бригада квалифицированных мастеров завершена предложить вам передовые средства, которые не только снабдят долговечную покров от холодных воздействий, но и дарят вашему домашнему пространству элегантный вид.
Мы практикуем с современными строительными материалами, утверждая долгосрочный срок службы службы и превосходные результирующие показатели. Изоляция внешней обшивки – это не только сокращение расходов на тепле, но и забота о окружающей среде. Спасательные технические средства, какие мы осуществляем, способствуют не только личному, но и сохранению природной среды.
Самое центральное: Утепление фасада цена с материалом у нас стартует всего от 1250 рублей за квадратный метр! Это бюджетное решение, которое превратит ваш домик в фактический тепличный локал с минимальными тратами.
Наши проекты – это не просто изоляция, это разработка области, в котором всякий элемент показывает ваш персональный стиль. Мы берем во внимание все твои требования, чтобы осуществить ваш дом еще больше дружелюбным и привлекательным.
Подробнее на веб-сайте компании
Не откладывайте труды о своем обители на потом! Обращайтесь к квалифицированным работникам, и мы сделаем ваш обиталище не только тепличным, но и стильнее. Заинтересовались? Подробнее о наших делах вы можете узнать на веб-сайте. Добро пожаловать в мир удобства и высоких стандартов.
Заказывайте утепление фасада дома под ключ у команды профессионалов с 15 летним опытом!

KeithBes

Слушай, компаньон! Я в курсе,  собственно что ты раздумываешь, для чего для тебя лазить по нашему сайту, но давай-ка я расскажу тебе отчего это круто, а?
https://santehkomplekt.md/4181/
 
 
 
 
 
Во-1-х, здесь ты найдешь вагон полезной инфы!  собственно что бы ты ни искал - от советов по саморазвитию до лайфхаков для улучшения обстановки - у нас есть все, что для тебя надо(надобно) для развития и вдохновения.
 
Но это еще не все! У нас тут целое объединение, как клуб "Без Карантина", где ты можешь знаться с крутыми ребятами, делиться своими мыслями и получать поддержку в любой ситуации.
 
А еще на нашем сайте всегда что-то случается! Промоакции, конкурсы, онлайн-мероприятия - в целом, все, дабы ты не заскучал и всегда оставался в курсе самых свежих направленностей.
 
И, старина, не тяни кота за хвост! Загляни на наш сайт и давай вкупе развиваться, общаться и веселиться! Я уверен, ты тут найдешь себе по-настоящему крутых приятелей и море позитива!