mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-30 16:51:57 +08:00
Documentation for 8b1eab204b
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
<!-- HTML header for doxygen 1.12.0-->
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
||||
<head>
|
||||
@@ -5,10 +6,15 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen 1.12.0"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>Algorithms_in_C++: math/least_common_multiple.cpp File Reference</title>
|
||||
<title>TheAlgorithms/C++: math/least_common_multiple.cpp File Reference</title>
|
||||
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
|
||||
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="../../jquery.js"></script>
|
||||
<script type="text/javascript" src="../../dynsections.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
|
||||
<script type="text/javascript">
|
||||
DoxygenAwesomeDarkModeToggle.init()
|
||||
</script>
|
||||
<script type="text/javascript" src="../../clipboard.js"></script>
|
||||
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="../../navtreedata.js"></script>
|
||||
@@ -18,14 +24,24 @@
|
||||
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
||||
<script type="text/javascript" src="../../search/search.js"></script>
|
||||
<script type="text/x-mathjax-config">
|
||||
MathJax.Hub.Config({
|
||||
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
||||
jax: ["input/TeX","output/HTML-CSS"],
|
||||
});
|
||||
<script type="text/javascript">
|
||||
window.MathJax = {
|
||||
options: {
|
||||
ignoreHtmlClass: 'tex2jax_ignore',
|
||||
processHtmlClass: 'tex2jax_process'
|
||||
},
|
||||
loader: {
|
||||
load: ['[tex]/ams']
|
||||
},
|
||||
tex: {
|
||||
macros: {},
|
||||
packages: ['base','configmacros','ams']
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
|
||||
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
|
||||
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
||||
<link href="../../doxygen-awesome.css" rel="stylesheet" type="text/css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
@@ -33,10 +49,11 @@ MathJax.Hub.Config({
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr id="projectrow">
|
||||
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
|
||||
<td id="projectalign">
|
||||
<div id="projectname">Algorithms_in_C++<span id="projectnumber"> 1.0.0</span>
|
||||
<div id="projectname">TheAlgorithms/C++<span id="projectnumber"> 1.0.0</span>
|
||||
</div>
|
||||
<div id="projectbrief">Set of algorithms implemented in C++.</div>
|
||||
<div id="projectbrief">All the algorithms implemented in C++</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -116,7 +133,9 @@ Include dependency graph for least_common_multiple.cpp:</div>
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d5/d8b/least__common__multiple_8cpp__incl.svg" width="227" height="111"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
</div><table class="memberdecls">
|
||||
</div>
|
||||
<p><a href="../../d4/d21/least__common__multiple_8cpp_source.html">Go to the source code of this file.</a></p>
|
||||
<table class="memberdecls">
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
||||
Functions</h2></td></tr>
|
||||
<tr class="memitem:a8ba1fc66e4134ab25b2602b323150563" id="r_a8ba1fc66e4134ab25b2602b323150563"><td class="memItemLeft" align="right" valign="top">unsigned int </td><td class="memItemRight" valign="bottom"><a class="el" href="#a8ba1fc66e4134ab25b2602b323150563">gcd</a> (unsigned int x, unsigned int y)</td></tr>
|
||||
@@ -131,6 +150,8 @@ Functions</h2></td></tr>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>Copyright 2020 </p><dl class="section author"><dt>Author</dt><dd>tjgurwara99</dd></dl>
|
||||
<p>A basic implementation of LCM function </p>
|
||||
|
||||
<p class="definition">Definition in file <a class="el" href="../../d4/d21/least__common__multiple_8cpp_source.html">least_common_multiple.cpp</a>.</p>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="a8ba1fc66e4134ab25b2602b323150563" name="a8ba1fc66e4134ab25b2602b323150563"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a8ba1fc66e4134ab25b2602b323150563">◆ </a></span>gcd()</h2>
|
||||
@@ -151,6 +172,8 @@ Functions</h2></td></tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p>Function for finding greatest common divisor of two numbers. @params two integers x and y whose gcd we want to find. </p><dl class="section return"><dt>Returns</dt><dd>greatest common divisor of x and y. </dd></dl>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d4/d21/least__common__multiple_8cpp_source.html#l00016">16</a> of file <a class="el" href="../../d4/d21/least__common__multiple_8cpp_source.html">least_common_multiple.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 16</span> {</div>
|
||||
<div class="line"><span class="lineno"> 17</span> <span class="keywordflow">if</span> (x == 0) {</div>
|
||||
<div class="line"><span class="lineno"> 18</span> <span class="keywordflow">return</span> y;</div>
|
||||
@@ -172,13 +195,8 @@ Functions</h2></td></tr>
|
||||
<div class="line"><span class="lineno"> 34</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> temp = y / x;</div>
|
||||
<div class="line"><span class="lineno"> 35</span> <span class="keywordflow">return</span> <a class="code hl_function" href="#a8ba1fc66e4134ab25b2602b323150563">gcd</a>(x, y - temp * x);</div>
|
||||
<div class="line"><span class="lineno"> 36</span>}</div>
|
||||
<div class="ttc" id="aleast__common__multiple_8cpp_html_a8ba1fc66e4134ab25b2602b323150563"><div class="ttname"><a href="#a8ba1fc66e4134ab25b2602b323150563">gcd</a></div><div class="ttdeci">unsigned int gcd(unsigned int x, unsigned int y)</div><div class="ttdef"><b>Definition</b> least_common_multiple.cpp:16</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d21/least__common__multiple_8cpp_a8ba1fc66e4134ab25b2602b323150563_cgraph.svg" width="54" height="60"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
|
||||
<div class="ttc" id="aleast__common__multiple_8cpp_html_a8ba1fc66e4134ab25b2602b323150563"><div class="ttname"><a href="#a8ba1fc66e4134ab25b2602b323150563">gcd</a></div><div class="ttdeci">unsigned int gcd(unsigned int x, unsigned int y)</div><div class="ttdef"><b>Definition</b> <a href="../../d4/d21/least__common__multiple_8cpp_source.html#l00016">least_common_multiple.cpp:16</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="aa8d0e241db517813725e721a152e3a25" name="aa8d0e241db517813725e721a152e3a25"></a>
|
||||
@@ -200,15 +218,12 @@ Here is the call graph for this function:</div>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p>Function for finding the least common multiple of two numbers. @params integer x and y whose lcm we want to find. </p><dl class="section return"><dt>Returns</dt><dd>lcm of x and y using the relation x * y = gcd(x, y) * lcm(x, y) </dd></dl>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d4/d21/least__common__multiple_8cpp_source.html#l00043">43</a> of file <a class="el" href="../../d4/d21/least__common__multiple_8cpp_source.html">least_common_multiple.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 43</span> {</div>
|
||||
<div class="line"><span class="lineno"> 44</span> <span class="keywordflow">return</span> x / <a class="code hl_function" href="#a8ba1fc66e4134ab25b2602b323150563">gcd</a>(x, y) * y;</div>
|
||||
<div class="line"><span class="lineno"> 45</span>}</div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d21/least__common__multiple_8cpp_aa8d0e241db517813725e721a152e3a25_cgraph.svg" width="144" height="60"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
||||
@@ -226,17 +241,14 @@ Here is the call graph for this function:</div>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p>Main function </p>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d4/d21/least__common__multiple_8cpp_source.html#l00078">78</a> of file <a class="el" href="../../d4/d21/least__common__multiple_8cpp_source.html">least_common_multiple.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 78</span> {</div>
|
||||
<div class="line"><span class="lineno"> 79</span> <a class="code hl_function" href="#a88ec9ad42717780d6caaff9d3d6977f9">tests</a>();</div>
|
||||
<div class="line"><span class="lineno"> 80</span> <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><span class="lineno"> 81</span>}</div>
|
||||
<div class="ttc" id="aleast__common__multiple_8cpp_html_a88ec9ad42717780d6caaff9d3d6977f9"><div class="ttname"><a href="#a88ec9ad42717780d6caaff9d3d6977f9">tests</a></div><div class="ttdeci">void tests()</div><div class="ttdef"><b>Definition</b> least_common_multiple.cpp:50</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d21/least__common__multiple_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="368" height="86"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
|
||||
<div class="ttc" id="aleast__common__multiple_8cpp_html_a88ec9ad42717780d6caaff9d3d6977f9"><div class="ttname"><a href="#a88ec9ad42717780d6caaff9d3d6977f9">tests</a></div><div class="ttdeci">void tests()</div><div class="ttdef"><b>Definition</b> <a href="../../d4/d21/least__common__multiple_8cpp_source.html#l00050">least_common_multiple.cpp:50</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="a88ec9ad42717780d6caaff9d3d6977f9" name="a88ec9ad42717780d6caaff9d3d6977f9"></a>
|
||||
@@ -254,39 +266,34 @@ Here is the call graph for this function:</div>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p>Function for testing the <a class="el" href="#aa8d0e241db517813725e721a152e3a25">lcm()</a> functions with some assert statements. </p>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d4/d21/least__common__multiple_8cpp_source.html#l00050">50</a> of file <a class="el" href="../../d4/d21/least__common__multiple_8cpp_source.html">least_common_multiple.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 50</span> {</div>
|
||||
<div class="line"><span class="lineno"> 51</span> <span class="comment">// First test on lcm(5,10) == 10</span></div>
|
||||
<div class="line"><span class="lineno"> 52</span> assert(((<span class="keywordtype">void</span>)<span class="stringliteral">"LCM of 5 and 10 is 10 but lcm function gives a different "</span></div>
|
||||
<div class="line"><span class="lineno"> 53</span> <span class="stringliteral">"result.\n"</span>,</div>
|
||||
<div class="line"><span class="lineno"> 54</span> <a class="code hl_function" href="#aa8d0e241db517813725e721a152e3a25">lcm</a>(5, 10) == 10));</div>
|
||||
<div class="line"><span class="lineno"> 55</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"First assertion passes: LCM of 5 and 10 is "</span> << <a class="code hl_function" href="#aa8d0e241db517813725e721a152e3a25">lcm</a>(5, 10)</div>
|
||||
<div class="line"><span class="lineno"> 56</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 55</span> std::cout << <span class="stringliteral">"First assertion passes: LCM of 5 and 10 is "</span> << <a class="code hl_function" href="#aa8d0e241db517813725e721a152e3a25">lcm</a>(5, 10)</div>
|
||||
<div class="line"><span class="lineno"> 56</span> << std::endl;</div>
|
||||
<div class="line"><span class="lineno"> 57</span> </div>
|
||||
<div class="line"><span class="lineno"> 58</span> <span class="comment">// Second test on lcm(2,3) == 6 as 2 and 3 are coprime (prime in fact)</span></div>
|
||||
<div class="line"><span class="lineno"> 59</span> assert(((<span class="keywordtype">void</span>)<span class="stringliteral">"LCM of 2 and 3 is 6 but lcm function gives a different "</span></div>
|
||||
<div class="line"><span class="lineno"> 60</span> <span class="stringliteral">"result.\n"</span>,</div>
|
||||
<div class="line"><span class="lineno"> 61</span> <a class="code hl_function" href="#aa8d0e241db517813725e721a152e3a25">lcm</a>(2, 3) == 6));</div>
|
||||
<div class="line"><span class="lineno"> 62</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Second assertion passes: LCM of 2 and 3 is "</span> << <a class="code hl_function" href="#aa8d0e241db517813725e721a152e3a25">lcm</a>(2, 3)</div>
|
||||
<div class="line"><span class="lineno"> 63</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 62</span> std::cout << <span class="stringliteral">"Second assertion passes: LCM of 2 and 3 is "</span> << <a class="code hl_function" href="#aa8d0e241db517813725e721a152e3a25">lcm</a>(2, 3)</div>
|
||||
<div class="line"><span class="lineno"> 63</span> << std::endl;</div>
|
||||
<div class="line"><span class="lineno"> 64</span> </div>
|
||||
<div class="line"><span class="lineno"> 65</span> <span class="comment">// Testing an integer overflow.</span></div>
|
||||
<div class="line"><span class="lineno"> 66</span> <span class="comment">// The algorithm should work as long as the result fits into integer.</span></div>
|
||||
<div class="line"><span class="lineno"> 67</span> assert(((<span class="keywordtype">void</span>)<span class="stringliteral">"LCM of 987654321 and 987654321 is 987654321 but lcm function"</span></div>
|
||||
<div class="line"><span class="lineno"> 68</span> <span class="stringliteral">" gives a different result.\n"</span>,</div>
|
||||
<div class="line"><span class="lineno"> 69</span> <a class="code hl_function" href="#aa8d0e241db517813725e721a152e3a25">lcm</a>(987654321, 987654321) == 987654321));</div>
|
||||
<div class="line"><span class="lineno"> 70</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Third assertion passes: LCM of 987654321 and 987654321 is "</span></div>
|
||||
<div class="line"><span class="lineno"> 70</span> std::cout << <span class="stringliteral">"Third assertion passes: LCM of 987654321 and 987654321 is "</span></div>
|
||||
<div class="line"><span class="lineno"> 71</span> << <a class="code hl_function" href="#aa8d0e241db517813725e721a152e3a25">lcm</a>(987654321, 987654321)</div>
|
||||
<div class="line"><span class="lineno"> 72</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 72</span> << std::endl;</div>
|
||||
<div class="line"><span class="lineno"> 73</span>}</div>
|
||||
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
|
||||
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
|
||||
<div class="ttc" id="aleast__common__multiple_8cpp_html_aa8d0e241db517813725e721a152e3a25"><div class="ttname"><a href="#aa8d0e241db517813725e721a152e3a25">lcm</a></div><div class="ttdeci">unsigned int lcm(unsigned int x, unsigned int y)</div><div class="ttdef"><b>Definition</b> least_common_multiple.cpp:43</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d21/least__common__multiple_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.svg" width="271" height="86"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
|
||||
<div class="ttc" id="aleast__common__multiple_8cpp_html_aa8d0e241db517813725e721a152e3a25"><div class="ttname"><a href="#aa8d0e241db517813725e721a152e3a25">lcm</a></div><div class="ttdeci">unsigned int lcm(unsigned int x, unsigned int y)</div><div class="ttdef"><b>Definition</b> <a href="../../d4/d21/least__common__multiple_8cpp_source.html#l00043">least_common_multiple.cpp:43</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- contents -->
|
||||
|
||||
Reference in New Issue
Block a user