- Syntax :
if (condition)
{
// block of code to be executed if the condition is true }
else
{
// block of code to be executed if the condition is false
}
- Program :
using namespace std;
int main() {
cout <<"\n----------------ELSE STATEMENT----------------\n";
int a;
cout<<"\nEnter your age :";
cin>>a;
if (a >= 18) {
cout <<"\nMajor";
}
else {
cout <<"\nMinor";
}
return 0;
}
- Output :
No comments:
Post a Comment