This section provides a collection of code examples written in various programming languages. Feel free to explore and use these examples as a starting point for your projects.
Python Code Example
Here's a simple Python script that prints "Hello, World!" to the console.
print("Hello, World!")
JavaScript Code Example
Below is a JavaScript function that reverses a string.
function reverseString(str) {
return str.split('').reverse().join('');
}
console.log(reverseString("Hello, World!")); // Output: !dlroW ,olleH
Java Code Example
The following Java code demonstrates how to calculate the factorial of a number.
public class Factorial {
public static void main(String[] args) {
int number = 5;
int factorial = 1;
for (int i = 1; i <= number; i++) {
factorial *= i;
}
System.out.println("Factorial of " + number + " is " + factorial);
}
}
C++ Code Example
Here's a C++ program that calculates the sum of two numbers.
#include <iostream>
int main() {
int num1, num2, sum;
std::cout << "Enter first number: ";
std::cin >> num1;
std::cout << "Enter second number: ";
std::cin >> num2;
sum = num1 + num2;
std::cout << "Sum of " << num1 << " and " << num2 << " is " << sum << std::endl;
return 0;
}
For more code examples and tutorials, check out our Programming Tutorials section!