{"id":113,"date":"2020-06-29T13:22:41","date_gmt":"2020-06-29T13:22:41","guid":{"rendered":"\/?p=113"},"modified":"2020-06-29T13:23:31","modified_gmt":"2020-06-29T13:23:31","slug":"113","status":"publish","type":"post","link":"http:\/\/suryaprakash.com.np\/?p=113","title":{"rendered":"C Program to Convert Binary Number into Decimal Number."},"content":{"rendered":"<p style=\"text-align: left;\">#include&lt;stdio.h&gt;<br \/>\n#include&lt;math.h&gt;<br \/>\nvoid main()<br \/>\n{<br \/>\nint n, sum=0, p=0,r,num, rem,check;<br \/>\nprintf(&#8220;enter the value of n\\n&#8221;);<br \/>\nscanf(&#8220;%d&#8221;,&amp;n);<br \/>\nnum=n;<br \/>\nwhile(num!=0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/this part is to check whether the input is binary or not<br \/>\n{<br \/>\nrem=num%10;<br \/>\nif(rem&gt;1)<br \/>\n{<br \/>\nprintf(&#8220;\\nthe number is not binary plz enter binary number only\\n&#8221;);<br \/>\ncheck=1;<br \/>\nexit(0);<br \/>\n}<\/p>\n<p>else<br \/>\n{<br \/>\nnum=num\/10;<br \/>\n}<\/p>\n<p>}<br \/>\nwhile(n!=0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/convertion part<br \/>\n{<br \/>\nr=n%10;<br \/>\nsum=sum+pow(2,p)*r;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/pow() fucntion is included in header file math.c<br \/>\nn=n\/10;<br \/>\np++;<\/p>\n<p>}<br \/>\nprintf(&#8220;the equivalent decimal number is %d&#8221;,sum);<br \/>\n}<\/p>\n<p><strong>OUTPUT<\/strong><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-114\" src=\"\/wp-content\/uploads\/2020\/06\/BINARY-TO-DECIMAL-300x131.png\" alt=\"\" width=\"300\" height=\"131\" srcset=\"\/wp-content\/uploads\/2020\/06\/BINARY-TO-DECIMAL-300x131.png 300w, \/wp-content\/uploads\/2020\/06\/BINARY-TO-DECIMAL.png 527w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>In this program the only binary number is allowed as input. There may have different logic for conversion. But the main thing we have to care about is correct result.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include&lt;stdio.h&gt; #include&lt;math.h&gt; void main() { int n, sum=0, p=0,r,num, rem,check; printf(&#8220;enter the value of n\\n&#8221;); scanf(&#8220;%d&#8221;,&amp;n); num=n; while(num!=0)&nbsp; &nbsp; &nbsp; &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,6],"tags":[],"_links":{"self":[{"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/113"}],"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=113"}],"version-history":[{"count":2,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":116,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/113\/revisions\/116"}],"wp:attachment":[{"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}