 # C++ Programming Code Examples

## C++ > If Else and Switch Case Code Examples

In C++ program, we have the variable i inside "Switch Braces", which means whatever the value of variable i is, the 'corresponding' case block gets executed. We have passed integer

Program checks whether an year ("integer") entered by the user is a leap year or not. All years which are "perfectly divisible" by 4 are leap years except for century years which is

In this example, if...else statement is used to check whether a number entered by the user is "even or odd". Integers which are perfectly "divisible by 2" are called even numbers. And

Takes an "arithmetic operator" (+, -, *, /) and two operands from an user and performs the operation on those two operands depending upon the operator entered by user. Program

To check whether the input year is a leap year or not a "leap year" in C++ Programming, you have to enter the year and start checking for the leap year. To check that the year is a leap

To check that the original number is equal to its reverse or not in C++, enter the number & reverse that number then check that reverse is equal to "original or not", before reversing

We have to enter some set of numbers. Now to find occurrence of positive, negative, zero from the given set of numbers, just check all the numbers using for loop whether number

Lets see a sample without break statement, then we will discuss switch case with break 'Switch Case' statement is mostly used with 'break statement' even though the break is

In sometimes you have a "condition" and you want to execute a block of code if condition is true and execute another piece of code if the same condition is false. This can be achieved

The statements inside if parenthesis (usually referred as if body) gets executed only when the given condition is true. If the condition is false then the statements "inside if body" are

In this control structure we have only one 'if' and one 'else', however we can have multiple 'else if' blocks. This is how it looks: If none of the 'condition is true' then these statements

A formal definition of an even number is that it is an integer of the form 'n = 2k', where k is an integer; it can then be shown that an odd number is an integer of the form "n = 2k + 1".

A simple c++ program which shows using of switch statement in c++. C++ Program which takes input a grade and display Grade Points Average GPA. Program takes inputs A,a, B,b,
"Switch statement" is multi-way decision that tests whether an expression 'matches' one of a number of "constant integer", and branches accordingly. 'Switch statement' that allows us
The "expressions" are evaluated in order; if an expressionis true, the 'statement' or 'block of statement' associated with it is executed, and this terminates the whole chain. The Code for
In Programming, The "if statement" by itself will execute a single statement, or a group of statements, when the expression following if evaluates to "true". It does nothing when the