{"id":11126,"date":"2022-09-01T06:13:24","date_gmt":"2022-09-01T06:13:24","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=11126"},"modified":"2023-10-02T15:53:50","modified_gmt":"2023-10-02T10:23:50","slug":"switch-case-exercise-solution","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/","title":{"rendered":"Microcontroller Embedded C Programming Lecture 96| switch case exercise solution contd."},"content":{"rendered":"<div class=\"boldgrid-section color4-background-color color-4-text-contrast bg-background-color\" style=\"background-size: cover; background-position: 50% 50%;\">\n<div class=\"container\">\n<div class=\"row hover-mobile-bg background-parallax color4-background-color color-4-text-contrast bg-background-color\" style=\"padding-top: 35px; padding-bottom: 0px;\" data-bg-overlaycolor=\"rgba(255,255,255,0.54)\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<div class=\"boldgrid-shortcode\" data-imhwpb-draggable=\"true\">\n\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 30px; border-width: 0px; line-height: 50px;\"><strong><span style=\"color: #000080;\">switch case exercise solution<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">In this post, let&#8217;s continue our <\/span><span style=\"font-weight: 400;\">previous<\/span><span style=\"font-weight: 400;\"><span style=\"color: #ff6600;\"><a style=\"color: #ff6600; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-95-switch-case-exercise-solution\/\" target=\"_blank\" rel=\"noopener\"> exercise<\/a><\/span>. <\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Let&#8217;s modify the code to handle the negative numbers.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">First, let&#8217;s check the case c, which is a circle. Here, after getting the radius(r) value, if(r &lt; 0), then you have to print &#8220;radius cannot be negative&#8221; and make the area -1. So, calculate the area only if the radius is positive. That&#8217;s why I use the else statement here.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">area=3.1415*r*r is calculated only when the radius is positive; otherwise, the area will be concluded as negative.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">switch<\/span>(code){\r\n<span style=\"color: #ff99cc;\">case<\/span> 'c':\r\n&nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #ff00ff;\">printf<\/span>(\"Circle Area calculation\\n\");\r\n&nbsp; &nbsp; &nbsp; <span style=\"color: #ff00ff;\">&nbsp;printf<\/span>(\"Enter radius(r) value:\");\r\n&nbsp; &nbsp; &nbsp; <span style=\"color: #ff00ff;\">&nbsp;scanf<\/span>(\"%f\",&amp;r);\r\n&nbsp; &nbsp; &nbsp; &nbsp;if( r &lt; 0){\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #ff00ff;\">printf<\/span>(\"radius cannot be -ve\\n\");\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; area = -1;\r\n&nbsp; &nbsp; &nbsp; &nbsp;}<span style=\"color: #ff99cc;\">else{<\/span>\r\n  &nbsp; &nbsp;        &nbsp;area = 3.1415 * r * r;\r\n&nbsp; &nbsp; &nbsp; &nbsp;}\r\n<span style=\"color: #ff99cc;\">  &nbsp; &nbsp;  break;<\/span><\/pre>\n<p class=\"\" style=\"text-align: center;\"><span style=\"color: #000000;\">Handle negative numbers code<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Here in the case &#8216;t&#8217;, we can consider two values: base and height. So, after reading the values b and h, let&#8217;s add the code.<\/span> <span style=\"font-weight: 400;\">if((b&lt;0)|| (h&lt;0)), then print \u201cbase or height cannot be -ve\u201d; else, it calculates the area<\/span><span style=\"font-weight: 400;\">.<\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">case<\/span> 't':\r\n&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #ff00ff;\">printf<\/span>(\"Triangle Area calculation\\n\");\r\n&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #ff00ff;\">printf<\/span>(\"Enter base(b) value:\");\r\n&nbsp; &nbsp; &nbsp; <span style=\"color: #ff00ff;\">&nbsp; scanf<\/span>(\"%f\",&amp;b);\r\n&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #ff00ff;\">printf<\/span>(\"Enter height(h) value:\");\r\n&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #ff00ff;\">scanf<\/span>(\"%f\",&amp;h);\r\n&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #ff99cc;\">if<\/span>( (b &lt; 0) || ( h &lt; 0)){\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #ff00ff;\">printf<\/span>(\"base or height cannot be -ve\\n\");\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; area = -1;\r\n&nbsp; &nbsp; &nbsp; &nbsp;}<span style=\"color: #ff99cc;\">else<\/span>{\r\n  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  area = ( b * h)\/2;\r\n&nbsp; &nbsp; &nbsp; &nbsp;}\r\n&nbsp; &nbsp; &nbsp; <span style=\"color: #ff99cc;\">&nbsp;break;<\/span><\/pre>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here in case \u2018z\u2019, we use 3 variables: a, b and h. So, if(((a &lt; 0) || (b &lt; 0) || (h &lt; 0))), if one among these become negative, this expression will be true, then you can print \u201cbase or height cannot be negative\u201d. That&#8217;s correct.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">case<\/span> 'z':\r\n  &nbsp; &nbsp;  <span style=\"color: #ff00ff;\">printf<\/span>(\"Trapezoid Area calculation\\n\");\r\n  &nbsp; &nbsp;  <span style=\"color: #ff00ff;\">printf<\/span>(\"Enter base1(a) value:\");\r\n  &nbsp; &nbsp;  <span style=\"color: #ff00ff;\">scanf<\/span>(\"%f\",&amp;a);\r\n  &nbsp; &nbsp;  <span style=\"color: #ff00ff;\">printf<\/span>(\"Enter base2(b) value:\");\r\n  &nbsp; &nbsp;  <span style=\"color: #ff00ff;\">scanf<\/span>(\"%f\",&amp;b);\r\n  &nbsp; &nbsp;  <span style=\"color: #ff00ff;\">printf<\/span>(\"Enter height(h) value:\");\r\n  &nbsp; &nbsp;  <span style=\"color: #ff00ff;\">scanf<\/span>(\"%f\",&amp;h);\r\n  &nbsp; &nbsp;  <span style=\"color: #ff99cc;\">if<\/span>( ( (a &lt; 0) || ( b &lt; 0) || (h &lt; 0) ) ){\r\n  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #ff00ff;\">printf<\/span>(\"base or height cannot be -ve\\n\");\r\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; area = -1;\r\n  &nbsp; &nbsp; &nbsp;}<span style=\"color: #ff99cc;\">else<\/span>{\r\n  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;area = (( a + b)\/2) * h;\r\n  &nbsp; &nbsp;  }\r\n  &nbsp; &nbsp;  <span style=\"color: #ff99cc;\">break;<\/span><\/pre>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In case \u2018s\u2019,&nbsp; if(a&nbsp; &lt;&nbsp; 0), then print \u201cside cannot be negative\u201d; Otherwise, calculate the area.&nbsp;<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"box-shadow: #cecece 0px 0px 0px 0px inset; font-size: 12px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">case<\/span> 's':\r\n<span style=\"color: #ff00ff;\">      printf<\/span>(\"Square Area calculation\\n\");\r\n<span style=\"color: #ff00ff;\">      printf<\/span>(\"Enter side(a) value:\");\r\n<span style=\"color: #ff00ff;\">      scanf<\/span>(\"%f\",&amp;a);\r\n<span style=\"color: #ff99cc;\">      if<\/span>( a &lt; 0){\r\n<span style=\"color: #ff00ff;\">            printf<\/span>(\"side cannot be -ve\\n\");\r\n            area = -1;\r\n      }<span style=\"color: #ff99cc;\">else<\/span>{\r\n            area = a * a;\r\n      }\r\n<span style=\"color: #ff99cc;\">      break;<\/span><\/pre>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And also do the same as a rectangle.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s execute the code and see the output. First, let me try a rectangle. Enter width value, I type 4, and length value I enter negative number -5. So, it shows width or length cannot be negative. That&#8217;s correct.<\/span><\/p>\n<figure id=\"attachment_11497\" aria-describedby=\"caption-attachment-11497\" style=\"width: 596px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-11497\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/09\/Figure-5-1024x528.png\" alt=\"switch case exercise solution\" width=\"596\" height=\"307\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1024x528.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-300x155.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-768x396.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-600x310.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-200x103.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-400x206.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-800x413.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5.png 1095w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><figcaption id=\"caption-attachment-11497\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Output<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let\u2019s try once again.&nbsp; Look at Figure 2, it shows the correct output.<\/span><\/p>\n<figure id=\"attachment_11498\" aria-describedby=\"caption-attachment-11498\" style=\"width: 663px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-11498\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/09\/Figure-6-1024x444.png\" alt=\"switch case exercise solution\" width=\"663\" height=\"287\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1024x444.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-300x130.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-768x333.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-600x260.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-200x87.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-400x174.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-800x347.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1200x521.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6.png 1321w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><figcaption id=\"caption-attachment-11498\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Output<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">We completed the discussion on <span style=\"color: #ff6600;\"><a style=\"color: #ff6600;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-93-switch-case-statement-in-c\/\" target=\"_blank\" rel=\"noopener\">switch\/case statements<\/a><\/span>, and so we are going to use switch case statements in our embedded programming as well. That&#8217;s all about a switch\/case statement.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\"><span style=\"color: #993366;\">Get the Microcontroller Embedded C Programming Full Course on<\/span> <a href=\"https:\/\/www.udemy.com\/course\/microcontroller-embedded-c-programming\/\">Here<\/a>.<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 20px; line-height: 23px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span>&nbsp;<\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; switch case exercise solution &nbsp; &nbsp; In this post, let&#8217;s continue our previous exercise. Let&#8217;s modify the code to handle the negative numbers. First, let&#8217;s check the case c, which is a circle. Here, after getting the radius(r) value, if(r &lt; 0), then you have to print &#8220;radius cannot be negative&#8221; and make the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11493,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[16],"class_list":["post-11126","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-microcontroller-embedded-c-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Handling Negative Numbers in Switch Case Exercises in C<\/title>\n<meta name=\"description\" content=\"Learn how to handle negative numbers in switch case statements with this comprehensive solution in C. Modify your code to handle negative\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Handling Negative Numbers in Switch Case Exercises in C\" \/>\n<meta property=\"og:description\" content=\"Learn how to handle negative numbers in switch case statements with this comprehensive solution in C. Modify your code to handle negative\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-01T06:13:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-02T10:23:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-8.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1269\" \/>\n\t<meta property=\"og:image:height\" content=\"523\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C Programming Lecture 96| switch case exercise solution contd.\",\"datePublished\":\"2022-09-01T06:13:24+00:00\",\"dateModified\":\"2023-10-02T10:23:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/\"},\"wordCount\":369,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-1-8.png\",\"keywords\":[\"Microcontroller Embedded C programming Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/\",\"name\":\"Handling Negative Numbers in Switch Case Exercises in C\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-1-8.png\",\"datePublished\":\"2022-09-01T06:13:24+00:00\",\"dateModified\":\"2023-10-02T10:23:50+00:00\",\"description\":\"Learn how to handle negative numbers in switch case statements with this comprehensive solution in C. Modify your code to handle negative\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-1-8.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-1-8.png\",\"width\":1269,\"height\":523,\"caption\":\"Figure 1. Handle negative numbers code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/switch-case-exercise-solution\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C Programming Lecture 96| switch case exercise solution contd.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Handling Negative Numbers in Switch Case Exercises in C","description":"Learn how to handle negative numbers in switch case statements with this comprehensive solution in C. Modify your code to handle negative","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/","og_locale":"en_US","og_type":"article","og_title":"Handling Negative Numbers in Switch Case Exercises in C","og_description":"Learn how to handle negative numbers in switch case statements with this comprehensive solution in C. Modify your code to handle negative","og_url":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-09-01T06:13:24+00:00","article_modified_time":"2023-10-02T10:23:50+00:00","og_image":[{"width":1269,"height":523,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-8.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C Programming Lecture 96| switch case exercise solution contd.","datePublished":"2022-09-01T06:13:24+00:00","dateModified":"2023-10-02T10:23:50+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/"},"wordCount":369,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-8.png","keywords":["Microcontroller Embedded C programming Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/","url":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/","name":"Handling Negative Numbers in Switch Case Exercises in C","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-8.png","datePublished":"2022-09-01T06:13:24+00:00","dateModified":"2023-10-02T10:23:50+00:00","description":"Learn how to handle negative numbers in switch case statements with this comprehensive solution in C. Modify your code to handle negative","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-8.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-8.png","width":1269,"height":523,"caption":"Figure 1. Handle negative numbers code"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/switch-case-exercise-solution\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C Programming Lecture 96| switch case exercise solution contd."}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/11126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=11126"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/11126\/revisions"}],"predecessor-version":[{"id":16079,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/11126\/revisions\/16079"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/11493"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=11126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=11126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=11126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}