Explain if-else statement in C++ with its syntax and proper example.
Answers
Answered by
7
Answer:
The if else statements are used to execute a set of statements if a specific boolean condition is true. Else it will execute another set of statements.
example program to use if-else to tell if a number is even or odd in c++.
#include <iostream>
using namespace std;
int main() {
cout << "Enter a number:";
int num;
cin >> num;
if(num%2 == 0){
cout << num << " is even";
}
else{
cout << num << " is odd";
}
return 0;
}
Explanation:
Answered by
0
This statement is used to decide whether a set of statements should be executed this statement is called two way branch
Explanation:
if (test condition)
Similar questions