Ticker

6/recent/ticker-posts

Program to display the month name. If number >13 then display invalid input using switch case.

Here we have to take a int type value by the user and using user value we have to display the corresponding month name eg. if user enter 5 then output should be may if entered number is greater than 12 then there is no month in such case we have to display "Invalid Input" as our output on the screen.

How does this Program work? 

The expression is evaluated once and compared with the values of each case

 - If there is a match, then the corresponding block of statements after the matching label are executed. For example, if the value of the expression is equal to variable n, then block of statements after case n: are executed until break statement is encountered. 

- If there is no match cought, then our default statements will be executed. 

- If we do not use break statement in our program, all statements after the matching label are executed. 

By the way, the default clause inside the switch statement is optional, on our requirment we can use default clause.

Post a Comment

0 Comments

Ad Code

Join our New Telegram Channel