The other example of if else is like a street or a road having only two ways to move forward and we select the one that is true that depends on the condition we used.This is like as
In this example we have a point where we are standing and want to move forward and we have only one choice to select a way for us.Examples of the if else statement are given bellow.
Syntax:
#include<iostream>
using namespace std; //header files
void main()
{
if(condition)
{
//body of if.
}
else
{
//body of else
}
}//body
of main.
Example 1:
Write a program to check that the given number is Even number or Odd number.
Solution:
Example 2:
Write a program to check that the given number is a Leap Year or not.
Solution:
Write a program to check that the given number is Even number or Odd number.
Solution:
#include<iostream>
using namespace std; //header files
void main()
{
int num; //num stand for number
cout<<"Enter a number
:"<<endl; //message
cin>>num;
//taking input from
the user.
if(num%2==0) //this is our condition to check the even number..because every even //number completely divisible by 2 and give remainder 0.
{
cout<<num<<" is Even Number"<<endl;
}
else
{
cout<<num<<" is Odd Number"<<endl;
}
cout<<"\n\n\n"<<endl; //used for next line.
system("pause");
}//body
of main.
Write a program to check that the given number is a Leap Year or not.
Solution:
#include<iostream>
using namespace std; //header files
void main()
{
int year;
cout<<"Enter a year :"<<endl; //message to display
cin>>year;
//taking input from
the user.
if(year%4==0) //this is our condition to
check the leap year...because every 4 yaer // after the month of febrary is 29 days.
{
cout<<year<<" IS A LEAP YEAR"<<endl;
}
else
{
cout<<year<<" IS NOT A LEAP
YEAR"<<endl;
}
cout<<"\n\n\n"<<endl; //used for next line.
system("pause");
}//body
of main.
TAGS:
if, programming, else, structure, java, if else, tutorial, decision, conditional, elseif, then, excel vba tutorial, excel vba example, excel vba examples, code, vb, science, computer, c++, if-else, control flow, control, visual studio, visual basic, condition, control structure, c language, learn java, java tutorial, branching statements, decisions, javascript, syntax, conditions, php, if else statement, structures, how to program, control structures, c (programming language), statement, vba, c programming, beginners, python, language, or, basic, script, nested if, simple if, introduction, else if, 2010, control structures in c++, java if else, if statements, visual basic for applications, features, high-level, kanthety, saradhi, sundeep, java tutorials, flowchart, how to use for loop in java, how to use for loop in laravel, how to use for loop in android studio, how to use for loop in c++, how to use for loop in excel, how to use for loop in jquery, how to use for loop in php, if-else block, branching, matlab, if conditions, java branching, java programming, if block, c program, pgc lectures:, java example, mechanical engineering, microsoft excel (software), university, java course, how to, statements, learn to code, indentation, coding, scripting language, lectures, how to use for loop in javascript, how to use for loop in matlab, how to use for loop in c programming, how to use for loop in python, how to use for loop in vba, how to use for loop in c++ in hindi,
TAGS:
if, programming, else, structure, java, if else, tutorial, decision, conditional, elseif, then, excel vba tutorial, excel vba example, excel vba examples, code, vb, science, computer, c++, if-else, control flow, control, visual studio, visual basic, condition, control structure, c language, learn java, java tutorial, branching statements, decisions, javascript, syntax, conditions, php, if else statement, structures, how to program, control structures, c (programming language), statement, vba, c programming, beginners, python, language, or, basic, script, nested if, simple if, introduction, else if, 2010, control structures in c++, java if else, if statements, visual basic for applications, features, high-level, kanthety, saradhi, sundeep, java tutorials, flowchart, how to use for loop in java, how to use for loop in laravel, how to use for loop in android studio, how to use for loop in c++, how to use for loop in excel, how to use for loop in jquery, how to use for loop in php, if-else block, branching, matlab, if conditions, java branching, java programming, if block, c program, pgc lectures:, java example, mechanical engineering, microsoft excel (software), university, java course, how to, statements, learn to code, indentation, coding, scripting language, lectures, how to use for loop in javascript, how to use for loop in matlab, how to use for loop in c programming, how to use for loop in python, how to use for loop in vba, how to use for loop in c++ in hindi,