javascript if else exercises
#include <iostream>
using namespace std;
int main() {
int x = 10;
if (x > 5) {
cout << "x is greater than 5" << endl;
} else {
cout << "x is not greater than 5" << endl;
}
return 0;
}
Explanation:
- #include <iostream>
: Includes the input-output stream library in C++.
- using namespace std;
: Allows the usage of elements in the standard C++ library without specifying the namespace.
- int main() { ... }
: The main function where the program execution starts.
- int x = 10;
: Declares an integer variable x
and assigns it the value 10.
- if (x > 5) { ... } else { ... }
: Checks if the value of x
is greater than 5. If true, it prints "x is greater than 5"; otherwise, it prints "x is not greater than 5".
- cout << "x is greater than 5" << endl;
: Outputs the text "x is greater than 5" to the console.
- cout << "x is not greater than 5" << endl;
: Outputs the text "x is not greater than 5" to the console.
- return 0;
: Indicates successful program execution and terminates the main()
function.