1if (condition) {
2 // block of code if condition is true
3}
4else {
5 // block of code if condition is false
6}
1 if( a == 10 ) {
2 cout << "Value of a is 10" << endl;
3 } else if( a == 20 ) {
4 // if else if condition is true
5 cout << "Value of a is 20" << endl;
6 }
1// Program to check whether an integer is positive or negative
2// This program considers 0 as a positive number
3
4#include <iostream>
5using namespace std;
6
7int main() {
8 int number;
9
10 cout << "Enter an integer: ";
11 cin >> number;
12 if (number >= 0) {
13 cout << "You entered a positive integer: " << number << endl;
14 }
15 else {
16 cout << "You entered a negative integer: " << number << endl;
17 }
18 cout << "This line is always printed.";
19 return 0;
20}
1#include <iostream>
2using namespace std;
3int main()
4{
5 int a;
6 cin>>a;
7 if(a= 0);
8 {
9 cout<<"a = " << a;
10 }
11}
12
13
1#include<iostream>
2using namespace std;
3int main(){
4 int eta;
5 cout<<"Ciao Utente inserisci la tua eta'! "<<"\n";
6 cin>>eta;
7 if(eta >= 18){
8 cout<<"Benvenuto al cinema!";
9 }
10}