Content for video c++
Content for video c++
#include <iostream>
using namespace std;
int main() {
cout << "Welcome to C++ Programming!" << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
cout << "This is my first C++ program." << endl;
return 0;
}
#include <iostream>
int main() {
std::cout << "This program does not use 'using namespace std;'";
return 0;
}
#include <iostream>
using namespace std;
int main() {
string name;
cout << "Enter your name: ";
cin >> name;
cout << "Hello, " << name << "!";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a = 10;
float b = 5.5;
char c = 'A';
bool d = true;
cout << a << " " << b << " " << c << " " << d;
return 0;
}
Demonstrate local and global variable scope.
#include <iostream>
using namespace std;
int x = 50; // Global variable
int main() {
int x = 10; // Local variable
cout << "Local x: " << x << endl;
cout << "Global x: " << ::x;
return 0;
}
#include <iostream>
using namespace std;
int main() {
const float PI = 3.1416;
cout << "Value of PI: " << PI;
return 0;
}
#include <iostream>
using namespace std;
void counter() {
static int count = 0;
count++;
cout << "Counter: " << count << endl;
}
int main() {
counter();
counter();
counter();
return 0;
}
Arithmetic operators.
#include <iostream>
using namespace std;
int main() {
int a = 10, b = 3;
cout << "Addition: " << (a + b) << endl;
cout << "Subtraction: " << (a - b) << endl;
cout << "Multiplication: " << (a * b) << endl;
cout << "Division: " << (a / b) << endl;
return 0;
}
Relational operators.
#include <iostream>
using namespace std;
int main() {
int x = 10, y = 20;
cout << (x == y) << endl;
cout << (x > y) << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cout << "Enter two numbers: ";
cin >> a >> b;
cout << "Sum: " << a + b;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
if (num % 2 == 0)
cout << "Even";
else
cout << "Odd";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cout << "Enter three numbers: ";
cin >> a >> b >> c;
if (a >= b && a >= c)
cout << "Largest: " << a;
else if (b >= a && b >= c)
cout << "Largest: " << b;
else
cout << "Largest: " << c;
return 0;
}
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 10; i++)
cout << i << " ";
return 0;
}
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 10; i++) {
if (i == 5)
break;
cout << i << " ";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 10; i++) {
if (i == 5)
continue;
cout << i << " ";
}
return 0;
}