switch…case statement in C

if...else statement provides support to control program flow. if statement make decisions based on conditions. It selects an action, if some condition is met. However, there exits situations where you want to make a decision from available choices. For example – select a laptop from available models, select a menu from available menu list etc.

switch...case statement gives ability to make decisions from fixed available choices. Rather making decision based on conditions. Using switch we can write a more clean and optimal code, that take decisions from available choices.

Read more

C program to create calculator using switch case and functions

Write a C program to create menu driven calculator that performs basic arithmetic operations (add, subtract, multiply and divide) using switch case and functions. The calculator should input two numbers and an operator from user. It should perform operation according to the operator entered and must take input in given format.

<number 1> <operator> <number 2>

Example
Input

5.2 - 3

Output

2.2

Read more

C program to check even or odd number using switch case

Write a C program to input number from user and check whether the number is even or odd using switch case. How to check even or odd using switch case in C programming. Logic to check whether a number is even or odd using switch case in C program.

Example
Input

Input number: 12

Output

Even number

Read more

Switch case programming exercises and solutions in C

switch case is a branching statement used to perform action based on available choices, instead of making decisions based on conditions. Using switch case you can write more clean and optimal code than if else statement.

switch case only works with integer, character and enumeration constants.

In this exercises we will focus on the use of switch case statement. We will learn where to implement switch case statement other than if else statement.

Read more

C program to find maximum between two numbers using switch case

Write a C program to input two numbers from user and find maximum between two numbers using switch case. How to find maximum or minimum between two numbers using switch case. Logic to find maximum between two numbers using switch case in C programming.

Example
Input

Input first number: 12
Input second number: 40

Output

Maximum: 40

Read more

C program to print number of days in a month using switch case

Write a C program to input month number and print total number of days in month using switch...case. C program to find total number of days in a month using switch...case. Logic to print number of days in a month using switch...case in C programming.

Example
Input

Input month number: 3

Output

Total number of days = 31

Read more