xxxxxxxxxx
int time = 22;
if (time < 10) {
cout << "Good morning.";
} else if (time < 20) {
cout << "Good day.";
} else {
cout << "Good evening.";
}
// Outputs "Good evening."
xxxxxxxxxx
if (condition1) {
// code block 1
}
else if (condition2){
// code block 2
}
else {
// code block 3
}
xxxxxxxxxx
if (5 == 4) {
//code you want to run if the condition is true
} else {
// code you want to run if the condition is false
}
xxxxxxxxxx
//1
if(condition) {
statement(s);
}
else {
statement(s);
}
//2
(condition) ? (true_statement) : (false_statement)
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
int a;
cin>>a;
if(a= 0);
{
cout<<"a = " << a;
}
}
xxxxxxxxxx
// Program to check whether an integer is positive, negative or zero
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter an integer: ";
cin >> number;
if (number > 0) {
cout << "You entered a positive integer: " << number << endl;
}
else if (number < 0) {
cout << "You entered a negative integer: " << number << endl;
}
else {
cout << "You entered 0." << endl;
}
cout << "This line is always printed.";
return 0;
}
xxxxxxxxxx
// C program to illustrate If statement
#include <stdio.h>
int main() {
int i = 20;
if (i < 15){
printf("i is smaller than 15");
}
else{
printf("i is greater than 15");
}
return 0;
}
xxxxxxxxxx
if (condition)
{
// Executes this block if
// condition is true
}
else
{
// Executes this block if
// condition is false
}
xxxxxxxxxx
int time = 20;
if (time < 18) {
cout << "Good day.";
} else {
cout << "Good evening.";
}
// Outputs "Good evening."