The if else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed. An if statement executes code conditionally depending on the result of the condition in parentheses.
When condition in parentheses is true it will enter to the block of if statement which is defined by curly braces like open braces and close braces. Opening bracket till the closing bracket is the scope of the if statement. The else block is optional and can be omitted. It runs if the if statement is false and does not run if the if statement is true because in that case if statement executes.
Syntax :
if ( condition )
{
// block of statement to be executed if condition is true ;
}
else
{
block of statement to be executed if condition is false ;
}
The program is written in C++ language and it checks whether a given character is a vowel or not. Here's how the program works:
#include<iostream> using namespace std; //aeiou AEIOU int main() { char c; cout<<"Enter The Character : "; cin>>c; if(c=='a' || c=='e' ||c=='i' ||c=='o' ||c=='u' || c=='A' || c=='E' ||c=='I' ||c=='O' ||c=='U') { cout<<c<<" is a Vowel"; } else { cout<<c<<" is not a Vowel"; } return 0; }
Enter The Character : s s is not a VowelTo download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions