{"id":154,"date":"2020-07-02T02:56:48","date_gmt":"2020-07-02T02:56:48","guid":{"rendered":"\/?p=154"},"modified":"2020-07-02T02:59:26","modified_gmt":"2020-07-02T02:59:26","slug":"prime-number","status":"publish","type":"post","link":"http:\/\/suryaprakash.com.np\/?p=154","title":{"rendered":"Prime Number"},"content":{"rendered":"<p><span style=\"color: #000080;\">\/\/To check whether the given number is prime or not<\/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 i, n;<\/span><br \/>\n<span style=\"color: #000080;\">printf(&#8220;enter the value of n\\t&#8221;);<\/span><br \/>\n<span style=\"color: #000080;\">scanf(&#8220;%d&#8221;,&amp;n);<\/span><br \/>\n<span style=\"color: #000080;\">for(i=2;i&lt;=n;i++)<\/span><br \/>\n<span style=\"color: #000080;\">{<\/span><br \/>\n<span style=\"color: #000080;\">if(n%i==0)<\/span><\/p>\n<p><span style=\"color: #000080;\">break;<\/span><\/p>\n<p><span style=\"color: #000080;\">}<\/span><br \/>\n<span style=\"color: #000080;\">if(i==n)<\/span><br \/>\n<span style=\"color: #000080;\">printf(&#8220;\\n%d is prime number&#8221;,n);<\/span><br \/>\n<span style=\"color: #000080;\">else<\/span><br \/>\n<span style=\"color: #000080;\">printf(&#8220;\\n%d is not prime&#8221;,n);<\/span><br \/>\n<span style=\"color: #000080;\">}<\/span><\/p>\n<p><span style=\"color: #000080;\"><strong>OUTPUT<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-156\" src=\"\/wp-content\/uploads\/2020\/07\/prime1-300x104.png\" alt=\"\" width=\"300\" height=\"104\" srcset=\"\/wp-content\/uploads\/2020\/07\/prime1-300x104.png 300w, \/wp-content\/uploads\/2020\/07\/prime1.png 463w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/> <img loading=\"lazy\" class=\"alignnone size-medium wp-image-155\" src=\"\/wp-content\/uploads\/2020\/07\/notPrime-300x166.png\" alt=\"\" width=\"300\" height=\"166\" srcset=\"\/wp-content\/uploads\/2020\/07\/notPrime-300x166.png 300w, \/wp-content\/uploads\/2020\/07\/notPrime.png 467w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><span style=\"color: #000000;\"><strong>Logic Description:<\/strong><\/span><\/p>\n<p>Since every number is divisible by 1.So i started to check the remainder value from 2. If the number is completely divisible by any number between 1 and and n except 1 and and n then the number is not prime else our count(i) will increase up-to n.When i and n are equal, the given number is never divided between 1 and the number because if the number is divided at once immediately our program break from the main logic and i and n never be equal. In this way prime and non-prime is checked.<\/p>\n<h1 style=\"text-align: center;\">Prime Number Between Range(1-1000)<\/h1>\n<p><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 i, j;<\/span><br \/>\n<span style=\"color: #000080;\">for(j=1;j&lt;=1000;j++)<\/span><\/p>\n<p><span style=\"color: #000080;\">{<\/span><\/p>\n<p><span style=\"color: #000080;\">for(i=2;i&lt;=j;i++)<\/span><br \/>\n<span style=\"color: #000080;\">{<\/span><br \/>\n<span style=\"color: #000080;\">if(j%i==0)<\/span><\/p>\n<p><span style=\"color: #000080;\">break;<\/span><\/p>\n<p><span style=\"color: #000080;\">}<\/span><br \/>\n<span style=\"color: #000080;\">if(j==i)<\/span><br \/>\n<span style=\"color: #000080;\">printf(&#8220;\\t%d&#8221;,j);<\/span><\/p>\n<p><span style=\"color: #000080;\">}<\/span><br \/>\n<span style=\"color: #000080;\">}<\/span><\/p>\n<p><strong>OUTPUT<\/strong><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-158\" src=\"\/wp-content\/uploads\/2020\/07\/prime-300x83.png\" alt=\"\" width=\"300\" height=\"83\" srcset=\"\/wp-content\/uploads\/2020\/07\/prime-300x83.png 300w, \/wp-content\/uploads\/2020\/07\/prime-768x214.png 768w, \/wp-content\/uploads\/2020\/07\/prime.png 953w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Here the range is fixed from 1 -1000. We can change the range according to our requirement.The range can also be defined at run time by taking input from keyboard.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/To check whether the given number is prime or not #include&lt;stdio.h&gt; void main() { int i, n; printf(&#8220;enter the value &hellip; <\/p>\n","protected":false},"author":1,"featured_media":157,"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\/154"}],"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=154"}],"version-history":[{"count":3,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":161,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions\/161"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/media\/157"}],"wp:attachment":[{"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}