{"id":168,"date":"2020-07-02T03:58:37","date_gmt":"2020-07-02T03:58:37","guid":{"rendered":"\/?p=168"},"modified":"2020-07-02T04:00:37","modified_gmt":"2020-07-02T04:00:37","slug":"hcf-and-lcm","status":"publish","type":"post","link":"http:\/\/suryaprakash.com.np\/?p=168","title":{"rendered":"HCF and LCM"},"content":{"rendered":"<p><span style=\"color: #000080;\">\/\/HCF and LCM<\/span><br \/>\n<span style=\"color: #000080;\">#include&lt;stdio.h&gt;<\/span><br \/>\n<span style=\"color: #000080;\">void main()<\/span><br \/>\n<span style=\"color: #000080;\">{<\/span><br \/>\n<span style=\"color: #000080;\">int n1,n2,a,b,LCM,HCF;<\/span><br \/>\n<span style=\"color: #000080;\">printf(&#8220;enter the value of two numbers:&#8221;);<\/span><br \/>\n<span style=\"color: #000080;\">scanf(&#8220;%d%d&#8221;,&amp;n1,&amp;n2);<\/span><br \/>\n<span style=\"color: #000080;\">a=n1;<\/span><br \/>\n<span style=\"color: #000080;\">b=n2;<\/span><br \/>\n<span style=\"color: #000080;\">while(n1!=n2)<\/span><br \/>\n<span style=\"color: #000080;\">{<\/span><br \/>\n<span style=\"color: #000080;\">if(n1&gt;n2)<\/span><br \/>\n<span style=\"color: #000080;\">{<\/span><br \/>\n<span style=\"color: #000080;\">n1=n1-n2;<\/span><br \/>\n<span style=\"color: #000080;\">n2=n2;<\/span><br \/>\n<span style=\"color: #000080;\">}<\/span><br \/>\n<span style=\"color: #000080;\">else<\/span><br \/>\n<span style=\"color: #000080;\">{<\/span><br \/>\n<span style=\"color: #000080;\">n1=n1;<\/span><br \/>\n<span style=\"color: #000080;\">n2=n2-n1;<\/span><br \/>\n<span style=\"color: #000080;\">}<\/span><br \/>\n<span style=\"color: #000080;\">}\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/coment Section<\/span><br \/>\n<span style=\"color: #000080;\">HCF=n1;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span style=\"color: #000000;\">\u00a0 \u00a0\/\/ At this point both the value of n1 and n2 so\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0writting HCF=n2 is same thing.<\/span><\/span><br \/>\n<span style=\"color: #000080;\">LCM=(a*b)\/HCF;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span style=\"color: #000000;\">\/\/ LCM= number1*number2\/HCF. Here we need\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ initial value of n1 and n2 which is equal to a and\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/\u00a0 \u00a0 b.<\/span><\/span><br \/>\n<span style=\"color: #000080;\">printf(&#8221; LCM=%d\\n HCM=%d&#8221;,LCM,HCF);<\/span><\/p>\n<p><span style=\"color: #000080;\">}<\/span><\/p>\n<p><strong><span style=\"color: #000000;\">OUTPUT<\/span><\/strong><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-169\" src=\"\/wp-content\/uploads\/2020\/07\/Hcf-300x118.png\" alt=\"\" width=\"300\" height=\"118\" srcset=\"\/wp-content\/uploads\/2020\/07\/Hcf-300x118.png 300w, \/wp-content\/uploads\/2020\/07\/Hcf.png 466w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>There are multiple logic to find hcf and lcm. This is the easiest i feel. If you find any confusion with the logic, you can comment on it.<\/p>\n<p>NOTE:- If you are using Turbo C compiler then you must have to include conio.h and insert\u00a0 getch(); to see the result.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/HCF and LCM #include&lt;stdio.h&gt; void main() { int n1,n2,a,b,LCM,HCF; printf(&#8220;enter the value of two numbers:&#8221;); scanf(&#8220;%d%d&#8221;,&amp;n1,&amp;n2); a=n1; b=n2; while(n1!=n2) { &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/168"}],"collection":[{"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=168"}],"version-history":[{"count":3,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/168\/revisions"}],"predecessor-version":[{"id":172,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/168\/revisions\/172"}],"wp:attachment":[{"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=168"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}