Thursday, August 5, 2021

condition statments if,if else,nasted if else in c++

    1. if statement

    2. if else statement

    3. nested if else

    4.     switch statement


if statement:

a.Use if condition to specify a block of code to be executed if a condition is true 
it only execute block of code only wgen given condition is true otherwise it does nothing
it work only when user enter a positive no otherwise is does nothing here is the output.

in the output user enter negative no and program not expected 

if else statement:

a)If-else statement executes a block of code
b)If condition is true if statement execute and block of if statement execute
c)Otherwise control is transfer to else part




in this program use else condition if the first condition is false then else condition executed
so in this code if number is not positive then it is negative.
program to check number is even or odd


the condition we applied if(number%2==0) mean that every time  when we  mode(%) with two it always be zero so the no that divide on 2 always zero if no is not divide by 2 else part executed mean it is odd no.

nested if else:
 

nested if-else is used to apply more then one if condition or else condition to make program more effective in above example if we enter  any negative even no in the program it print even but we only want positive no so to deal with so we write the program for it 







No comments:

Post a Comment

How to apply for Canada visa?

  Applying for a Canada Visa: A Comprehensive Guide Explore the Beauty of Canada - Your Step-by-Step Visa Application Guide Introduction Can...