If statement in C++
IF the condition is true then the block of statement is executed and if the condition is false the the block of statement is ignored and the control is transferred to the next statement after if statement.
Syntax to write IF statement:
if (relational or logical condition)
{
Block of statements
}
Next statement after if:Flowchart of if Statement
For Example:
A Program to check number is positive and how many digits number have
Code:
If is a keyword in C++ language. It is used to execute or ignore a set of statements after testing it.A condition is a relational or logical expression and it produces either true(means 1) or false(means 0) result.
IF the condition is true then the block of statement is executed and if the condition is false the the block of statement is ignored and the control is transferred to the next statement after if statement.
Syntax to write IF statement:
if (relational or logical condition)
{
Block of statements
}
Next statement after if:Flowchart of if Statement
For Example:
A Program to check number is positive and how many digits number have
Code:
- #include<iostream>
- using namespace std;
- int main()
- {int num;
- cout<<" Enter Number btween 1 to 999 ";
- cin>>num;
- if(num>0)
- { cout<<num<<" is a Positive Number "<<endl;
- if(num<10)
- {
- cout<<num<<" is a ONE digit Number ";
- }
- else if(num<100)
- {
- cout<<num<<" is a TWO digit Number ";
- }
- else if(num<1000)
- {
- cout<<num<<" is a Three digit Number ";
- }
- }
- return 0;}
it's not running correctly
ReplyDeleteyup....in this program else if ladder will be used...
ReplyDeleteThis comment has been removed by the author.
ReplyDelete#include
ReplyDelete#include
void main()
{
int num;
cout<<" Enter Number between 1 to 999 ";
cin>>num;
if(num>0)
{ cout<<num<<" is a Positive Number "<<endl;
if(num<10)
{
cout<<num<<" is a ONE digit Number ";
}
else if(num<100)
{
cout<<num<<" is a TWO digit Number ";
}
else if(num<1000)
{
cout<<num<<" is a Three digit Number ";
}
}
else
cout<<num<<" is a negtive number or zero";
}
include header files.....
DeleteHello how about using switch in the C++ whats the program goes ????
Deletenot complrtly explained
ReplyDeletesar please tell us sepratly about nested if and nested if else
ReplyDeleteSee Here
Deletehttp://fahad-cprogramming.blogspot.com/p/list-of-all-chapters.html
Thanks a lot. I finally understand about if nested in C++
ReplyDeleteYour Welcome
DeleteI can't find nested if program can u write again?
ReplyDeletei want source code for shoe shop management system please
ReplyDelete