Universal Code Snippet
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}#include <iostream>
#include <string>
using namespace std;
int main() {
string name;
cout << "Enter your name: ";
cin >> name;
cout << "Hello, " << name << "!" << endl;
return 0;
}#include <iostream>
using namespace std;
int main() {
int age = 20;
if (age >= 18) {
cout << "You are an adult." << endl;
} else {
cout << "You are a minor." << endl;
}
return 0;
}#include <iostream>
using namespace std;
int main() {
cout << "For loop:" << endl;
for (int i = 1; i <= 5; i++) {
cout << i << " ";
}
cout << endl;
cout << "While loop:" << endl;
int j = 1;
while (j <= 5) {
cout << j << " ";
j++;
}
cout << endl;
return 0;
}#include <iostream>
using namespace std;
int add(int a, int b) {
return a + b;
}
int main() {
cout << "Sum: " << add(10, 20) << endl;
return 0;
}#include <iostream>
using namespace std;
int main() {
int numbers[] = {10, 20, 30, 40, 50};
int size = sizeof(numbers) / sizeof(numbers[0]);
for (int i = 0; i < size; i++) {
cout << "Element " << i << ": " << numbers[i] << endl;
}
return 0;
}#include <iostream>
#include <string>
using namespace std;
int main() {
string str1 = "Hello";
string str2 = " World";
cout << "Length: " << str1.length() << endl;
str1 += str2;
cout << "Concatenated: " << str1 << endl;
string str3 = str1;
cout << "Copied: " << str3 << endl;
return 0;
}#include <iostream>
using namespace std;
int main() {
float a = 15.0, b = 4.0;
cout << "Add: " << a + b << endl;
cout << "Subtract: " << a - b << endl;
cout << "Multiply: " << a * b << endl;
cout << "Divide: " << a / b << endl;
return 0;
}