{"id":162,"date":"2021-09-30T07:51:14","date_gmt":"2021-09-30T07:51:14","guid":{"rendered":"https:\/\/ethosspace.com\/programmers\/?p=162"},"modified":"2021-11-03T14:09:11","modified_gmt":"2021-11-03T14:09:11","slug":"c-program-for-smallest-of-three-number-using-ternary-operator","status":"publish","type":"post","link":"https:\/\/ethosspace.com\/programmers\/c-program-for-smallest-of-three-number-using-ternary-operator\/","title":{"rendered":"C Program for smallest, largest of three number using ternary operator"},"content":{"rendered":"\n<p>Below running code will accept 3 Numbers from user.<\/p>\n\n\n\n<p>Based on results given in expression in ternary operator program will return smallest number<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Program Name: C Program to find smallest number using Ternary operator\n#include &lt;stdio.h&gt;\n\nvoid main()\n{\n    int num1,num2,num3;\n    int counter;\n    printf(\"\\n\\tEnter first Integer Number\\t\");\n    scanf(\"%d\",&amp;num1);\n    printf(\"\\n\\tEnter Second Integer Number\\t\");\n    scanf(\"%d\",&amp;num2);\n    printf(\"\\n\\tEnter Third Integer Number\\t\");\n    scanf(\"%d\",&amp;num3);\n    \n    \n    \/\/ Ternary operator\n    counter = (num1 &lt; num2) ? (num1 &lt; num3 ? num1:num3) : (num2 &lt; num3 ? num2:num3);\n    \n    printf(\"\\n\\t Minimum of 3 Number is %d\", counter);\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n        Enter first Integer Number      11\n\n        Enter Second Integer Number     90\n\n        Enter Third Integer Number      32\n\n         Minimum of 3 Number is 11<\/code><\/pre>\n\n\n\n<p>To find another method <a href=\"https:\/\/ethosspace.com\/programmers\/c-program-for-smallest-of-three-numbers-without-comparing\/\" title=\"https:\/\/ethosspace.com\/programmers\/c-program-for-smallest-of-three-numbers-without-comparing\/\">Click here<\/a> . Program to find smallest number without comparison <\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Program to find largest or greatest of 3 number using ternary operator<\/h2>\n\n\n\n<p>Accept 3 numbers from user using scanf. User ternary operator to compare them and print result using printf. Here is complete code.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-c\" data-lang=\"C\"><code>\/\/ Program Name: C Program to find largest number using Ternary operator\n#include &lt;stdio.h&gt;\n\nvoid main()\n{\n    int num1,num2,num3;\n    int counter;\n    printf(&quot;\\n\\tEnter first Integer Number\\t&quot;);\n    scanf(&quot;%d&quot;,&num1);\n    printf(&quot;\\n\\tEnter Second Integer Number\\t&quot;);\n    scanf(&quot;%d&quot;,&num2);\n    printf(&quot;\\n\\tEnter Third Integer Number\\t&quot;);\n    scanf(&quot;%d&quot;,&num3);\n    \n    \n    \/\/ Ternary operator\n    counter = (num1 &gt; num2) ? (num1 &gt; num3 ? num1:num3) : (num2 &gt; num3 ? num2:num3);\n    \n    printf(&quot;\\n\\t Largest of 3 Number is %d&quot;, counter);\n}<\/code><\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>Enter first Integer Number\t4\nEnter Second Integer Number\t5\nEnter Third Integer Number\t6\nLargest of 3 Number is 6<\/code><\/pre><\/div>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Below running code will accept 3 Numbers from user. Based on results given in expression in ternary operator program will return smallest number Output To find another method Click here . Program to find smallest number without comparison Program to find largest or greatest of 3 number using ternary operator Accept 3 numbers from user [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-162","post","type-post","status-publish","format-standard","hentry","category-c-language"],"aioseo_notices":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"sparkling-featured":false,"sparkling-featured-fullwidth":false,"tab-small":false},"uagb_author_info":{"display_name":"program45_-rt8nb","author_link":"https:\/\/ethosspace.com\/programmers\/author\/program45_-rt8nb\/"},"uagb_comment_info":0,"uagb_excerpt":"Below running code will accept 3 Numbers from user. Based on results given in expression in ternary operator program will return smallest number Output To find another method Click here . Program to find smallest number without comparison Program to find largest or greatest of 3 number using ternary operator Accept 3 numbers from user&hellip;","_links":{"self":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/comments?post=162"}],"version-history":[{"count":4,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":859,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/162\/revisions\/859"}],"wp:attachment":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/media?parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/categories?post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/tags?post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}