# C Programming Code Examples

## C > If Else and Switch Case Code Examples

Break Statements are useful when you want your program-flow to come out of the switch body. Whenever break is encountered in the switch body, the control comes out of switch

The if...else statement executes some code if the test expression is true (nonzero) & some other code if the test expression is false (0). If test expression is true, codes inside the body

C Program code to Check Whether a number is even or odd using if else. A number exactly divisible by 2 leaving no remainder, is known as even number. Any number modulo divided

Take the two integers as input and store it in the variables x & y respectively. Using if, else statements check if x is equal to y. If they are equal, then print the output as "x and y are...

Program to find electricity bill using if else in C. Input unit consumed by customer in some variable say unit and if unit consumed less or equal to 50 units. Then amt = unit * 0.50. Unit

C Program coding input cost price and selling price of a product & check profit or loss. Logic to find profit or loss. In primary mathematics classes, you all have learned about profit and

Input number from user and check whether the number is even or odd using switch case. A number is said even number if it is exactly divisible by 2. In C we use Modulo operator...

C Language Program takes the given integer & checks whether the integer is odd or even. Take the integer to be checked as input. Find the remainder of the integer by dividing it by

Take the integer which you want to check as input and store it in a variable number. Using if, else statements check whether the integer is Greater or Lesser than zero. If it is greater...

If a number is exactly divisible by 2 then its an even number else it is an odd number. In this we have shared 2 ways to check whether the input number is even or odd. Using Modulus

C Language program check leap year using if else. Wikipedia states Leap Year as a special year containing one extra day i.e. total 366 days in a year. A year is said to be leap year,...

English Alphabets a, e, i, o, u both lowercase & uppercase are known as vowels. Alphabets other than Vowels are known as Consonants. Input an alphabet from user. Store it in some

C Programming Language check whether an alphabet is Vowel or Consonant using if else. English alphabets a, e, i, o, u both lowercase & uppercase are known as vowels. Alphabets

How to check whether a character is alphabet or not in C programming. Every printable and nonprintable symbol is treated as a character and has an ASCII value. ASCII value is unique

C Programming input a character and Check whether given character is alphabet, digit or special character using if else. A character is alphabet if it in between a-z or A-Z. Character

C program code to input character from user and check whether character is Uppercase or Lowercase alphabet using If Else Statement. Input a character from user. Store it in some

Check whether a number is divisible by 5 and 13 or not using if else. A number is divisible by some other number if it gives 0 as remainder. To check if a number is exactly divisible by a...

We will use the above logic inside if to check number for Negative, Positive or Zero. Step by step Descriptive Logic to check negative, positive or zero. Input a number from user in

C program input sides of a triangle and check whether a Triangle is Equilateral, Scalene or Isosceles triangle using if else. Triangle is said Equilateral Triangle, if all its sides are equal. If

C Program code to check whether a Triangle is valid or not if angles are given using if else. Input all three angles of triangle in a variable say angle1, angle2 and angle3. Find sum of...

C Program code to input side of a Triangle & check whether triangle is valid or not using if else. A triangle is valid if sum of its two sides is greater than the third side. Means if a, b, c

C program to input amount from user & print minimum number of notes (Rs. 500, 100, 50, 20, 10, 5, 2, 1) required for the amount. Input amount from user. Store it in a variable 'amt'.

Create menu driven Calculator that performs basic mathematic operations (Add, Subtract, Multiply, Divide) use switch case & functions. The calculator should input two numbers and

Write a C program code to input marks of five subjects Computer, Chemistry, Mathematics, Biology, Physics & Calculate Percentage and grade according to given conditions. Student

C language program input week number(1-7) & print the corresponding day of week name using if else. Input week day number. Store it in some variable say week. And print Monday

Step by step descriptive logic to find roots of Quadratic Equation using Switch Case. Input coefficients of quadratic equation. Store it in some variable say a, b, c. Find discriminant of

Find all roots of a quadratic equation using if else. Input coefficients of quadratic equation from user. Store it in some variable say a, b, c. Find Discriminant of the an Equation, using...

Write a C program to find maximum between three numbers using Ladder If Else or nested if. We will continue our discussion and we will write code to find maximum between three...

C Program input two numbers from user and find maximum between two numbers using switch case. Input two numbers. Store it in a variable say j1 & j2. Switch expression j1 > j2

Finding maximum in general is comparison of two numbers. In C programming we compare two quantities using relational operator. Use either > or < operator to compare 2 numbers

Program code enter Month number between 1-12 and print number of days in month using If Else. Input month number from user. Store it in a variable say month and for each month

C program code input week number(1-7) and print day of week name using switch case. C program to find week day name using switch case. Input day number from user. Store it in

C Program to Input month number and Print Total Number of Days in Month using switch case. Input month number from user. Store it in some variable say month. Switch the value

Compare three integer variables is one of the simplest c program you can write at ease. In this program, you can either take input from user using scanf() function or statically define

Comparing two integer variables is one of the simplest c program you can write at ease. In this program, you can either take input from user using scanf() function or statically define

C Language check if a number is positive or negative using nested if...else. This program takes a number from user & checks whether that number is either positive or negative or

Page 1 Page 2