{"id":121,"date":"2020-06-30T05:04:47","date_gmt":"2020-06-30T05:04:47","guid":{"rendered":"\/?p=121"},"modified":"2020-06-30T05:06:44","modified_gmt":"2020-06-30T05:06:44","slug":"switch-case-statement","status":"publish","type":"post","link":"http:\/\/suryaprakash.com.np\/?p=121","title":{"rendered":"Switch Case Statement"},"content":{"rendered":"<p>\/\/use of case statement<br \/>\n#include&lt;stdio.h&gt;<br \/>\nvoid main()<br \/>\n{<br \/>\nint choice, a,b,result;<br \/>\nprintf(&#8220;Enter the choice\\n1.Add\\n2.Substract\\n3.Multiply\\n4.Division\\n &#8220;);<br \/>\nscanf(&#8220;%d&#8221;,&amp;choice);<br \/>\nprintf(&#8220;enter the two numbers&#8221;);<br \/>\nscanf(&#8220;%d%d&#8221;,&amp;a,&amp;b);<br \/>\nswitch(choice)<br \/>\n{<br \/>\ncase 1: result=a+b;<br \/>\nprintf(&#8220;\\nthe sum of two number is %d&#8221;, result);<br \/>\nbreak;<br \/>\ncase 2: result=a-b;<br \/>\nprintf(&#8220;\\nthe difference is %d&#8221;, result);<br \/>\nbreak;<br \/>\ncase 3: result= a*b;<br \/>\nprintf(&#8220;\\nthe multiplicaion is %d&#8221;,result);<br \/>\nbreak;<br \/>\ncase 4: if(b==0)<br \/>\n{<br \/>\nprintf(&#8220;\\nthe denomininator is zero so division is not possible&#8221;);<\/p>\n<p>}<br \/>\nelse<br \/>\n{<br \/>\nfloat result=a\/b;<br \/>\nprintf(&#8220;\\nthe devision is %f&#8221;,result);<br \/>\n}<br \/>\nbreak;<br \/>\ndefault: printf(&#8220;\\n wrong choice&#8221;);<br \/>\n}<br \/>\nprintf(&#8220;\\nThank You&#8221;);<br \/>\n}<\/p>\n<p><strong>OUTPUT<\/strong><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-124\" src=\"\/wp-content\/uploads\/2020\/06\/division1-300x194.png\" alt=\"\" width=\"300\" height=\"194\" srcset=\"\/wp-content\/uploads\/2020\/06\/division1-300x194.png 300w, \/wp-content\/uploads\/2020\/06\/division1.png 454w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/> <img loading=\"lazy\" class=\"alignnone size-medium wp-image-125\" src=\"\/wp-content\/uploads\/2020\/06\/Multiplication-300x192.png\" alt=\"\" width=\"300\" height=\"192\" srcset=\"\/wp-content\/uploads\/2020\/06\/Multiplication-300x192.png 300w, \/wp-content\/uploads\/2020\/06\/Multiplication.png 483w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/> <img loading=\"lazy\" class=\"alignnone size-medium wp-image-126\" src=\"\/wp-content\/uploads\/2020\/06\/substract-300x208.png\" alt=\"\" width=\"300\" height=\"208\" srcset=\"\/wp-content\/uploads\/2020\/06\/substract-300x208.png 300w, \/wp-content\/uploads\/2020\/06\/substract.png 474w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/> <img loading=\"lazy\" class=\"alignnone size-medium wp-image-123\" src=\"\/wp-content\/uploads\/2020\/06\/Division-300x188.png\" alt=\"\" width=\"300\" height=\"188\" srcset=\"\/wp-content\/uploads\/2020\/06\/Division-300x188.png 300w, \/wp-content\/uploads\/2020\/06\/Division.png 464w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/> <img loading=\"lazy\" class=\"alignnone size-medium wp-image-122\" src=\"\/wp-content\/uploads\/2020\/06\/Add-300x190.png\" alt=\"\" width=\"300\" height=\"190\" srcset=\"\/wp-content\/uploads\/2020\/06\/Add-300x190.png 300w, \/wp-content\/uploads\/2020\/06\/Add.png 535w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>In this statement only one operation will be selected to execute according to our choice. Here, 5 output result for my different choice at different time. so keep in your mind that this statement are used only when you have multiple options but have to choose only one just like MCQ. In online examination of MCQ pattern same concept is used though may have other programming language.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/use of case statement #include&lt;stdio.h&gt; void main() { int choice, a,b,result; printf(&#8220;Enter the choice\\n1.Add\\n2.Substract\\n3.Multiply\\n4.Division\\n &#8220;); scanf(&#8220;%d&#8221;,&amp;choice); printf(&#8220;enter the two numbers&#8221;); &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\/121"}],"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=121"}],"version-history":[{"count":2,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":128,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions\/128"}],"wp:attachment":[{"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/suryaprakash.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}