Lompat ke konten Lompat ke sidebar Lompat ke footer

divide the numerator and denominator by the same number

Least Common Denominator (LCD)

The lowest Common Denominator or Least Common Denominator is the Lowest common multiple of the denominators of a set of fractions.

Common denominator : when the denominators of two or more fractions are the same.
To the lowest degree Common denominator is the smallest of all common denominators.
Why do we need LCD ?
It simplifies increase, subtraction and comparing fraction.
Common Denominator fundament Be simply evaluated by multiplying the denominators. In this case, 3 * 6 = 18


But that may non always be to the lowest degree common denominator, as in that shell Liquid crystal display = 6 and not 18. LCD is actually Lowest common multiple of denominators.
Examples :

LCD for fractions 5/12 and 7/15 is 60. We can write both fractions as 25/60 and 28/60 so that they nates be added and  subtracted easily.  LCD for fractions 1/3 and 4/7 is 21.

Instance Problem : Given two fractions, recover their sum using to the lowest degree common dominator.
Examples:

Input signal :  1/6  +  7/15     Output : 19/30          Account : LCM of 6 and 15 is 30.           So, 5/30  +  14/30 = 19/30  Input :  1/3  +  1/6 Output : 3/6          Explanation : Least common multiple of 3 and 6 is 6.           So, 2/6  +  1/6 = 3/6

Note* These answers backside be further simplified by Anomalous cancellation.

C++

#include <iostream>

using namespace std;

int gcd( int a, int b)

{

if (a == 0)

return b;

return gcd(b % a, a);

}

int lcm( int a, int b)

{

regaining (a * b) / gcd(a, b);

}

vacuum printSum( int num1, int den1,

int num2, int den2)

{

int lcd = lcm(den1, den2);

num1 *= (LCD / den1);

num2 *= (lcd / den2);

int res_num = num1 + num2;

cout << res_num << "/" << lcd;

}

int main()

{

int num1 = 1, den1 = 6;

int num2 = 7, den2 = 15;

printSum(num1, den1, num2, den2);

reelect 0;

}

Java

public class GFG {

static int gcd( int a, int b)

{

if (a == 0 )

return b;

return gcd(b % a, a);

}

static int lcm( int a, int b)

{

return (a * b) / gcd(a, b);

}

static void printSum( int num1, int den1,

int num2, int den2)

{

int LCD = lcm(den1, den2);

num1 *= (lcd / den1);

num2 *= (lcd / den2);

int res_num = num1 + num2;

System.out.print( res_num + "/" + lcd);

}

public static void main(String args[])

{

int num1 = 1 , den1 = 6 ;

int num2 = 7 , den2 = 15 ;

printSum(num1, den1, num2, den2);

}

}

Python3

def gcd(a, b):

if (a = = 0 ):

return b

return gcd(b % a, a)

def lcm(a, b):

return (a * b) / gcd(a, b)

def printSum(num1, den1,

num2, den2):

liquid crystal display = lcm(den1, den2);

num1 * = (lcd / den1)

num2 * = (lcd / den2)

res_num = num1 + num2;

print ( int (res_num) , "/" ,

int (lcd))

num1 = 1

den1 = 6

num2 = 7

den2 = 15

printSum(num1, den1, num2, den2);

C#

using System of rules;

class GFG {

static int gcd( int a, int b)

{

if (a == 0)

return b;

return gcd(b % a, a);

}

static int lcm( int a, int b)

{

return (a * b) / gcd(a, b);

}

static void printSum( int num1, int den1,

int num2, int den2)

{

int lcd = lcm(den1, den2);

num1 *= (LCD / den1);

num2 *= (liquid crystal display / den2);

int res_num = num1 + num2;

Console.Write( res_num + "/" + lcd);

}

public unmoving void Main ()

{

int num1 = 1, den1 = 6;

int num2 = 7, den2 = 15;

printSum(num1, den1, num2, den2);

}

}

PHP

<?php

function gcd( $a , $b )

{

if ( $a == 0)

turn back $b ;

render gcd( $b % $a , $a );

}

function lcm( $a , $b )

{

return ( $a * $b ) / gcd( $a , $b );

}

function printSum( $num1 , $den1 ,

$num2 , $den2 )

{

$LCD = lcm( $den1 , $den2 );

$num1 *= ( $lcd / $den1 );

$num2 *= ( $lcd / $den2 );

$res_num = $num1 + $num2 ;

echo $res_num . "/" . $lcd ;

}

$num1 = 1;

$den1 = 6;

$num2 = 7;

$den2 = 15;

printSum( $num1 , $den1 , $num2 , $den2 );

?>

Javascript

<handwriting>

run gcd(a , b)

{

if (a == 0)

return b;

return gcd(b % a, a);

}

function lcm(a , b)

{

return (a * b) / gcd(a, b);

}

function printSum(num1 , den1 , num2 , den2)

{

var lcd = lcm(den1, den2);

num1 *= (lcd / den1);

num2 *= (lcd / den2);

volt-ampere res_num = num1 + num2;

document.write(res_num + "/" + lcd);

}

var num1 = 1, den1 = 6;

var num2 = 7, den2 = 15;

printSum(num1, den1, num2, den2);

</script>

Output :

19/30

This clause is contributed away Shubham Rana. If you like GeeksforGeeks and would like to contribute, you crapper also write an clause using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks principal page and help strange Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed in a higher place.


divide the numerator and denominator by the same number

Source: https://www.geeksforgeeks.org/least-common-denominator-lcd/

Posting Komentar untuk "divide the numerator and denominator by the same number"