In today's tech-driven world, programming skills are more important than ever. Whether you're a beginner or an experienced developer, learning C and PHP can significantly boost your career prospects. This article offers a detailed C and PHP programming problem bank with solutions, aimed at helping you improve your coding skills.
C is a low-level language widely used in system software, embedded systems, and high-performance applications. Below are some classic C programming problems:
Write a function to calculate the factorial of a given number.
#include <stdio.h>
int factorial(int n) {
if (n < 0) return -1;
if (n == 0) return 1;
return n * factorial(n - 1);
}
int main() {
int num = 5;
printf("Factorial of %d is %d\n", num, factorial(num));
return 0;
}
Write a function to check if a given number is a prime number.
#include <stdio.h>
#include <stdbool.h>
bool isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
int main() {
int num = 11;
if (isPrime(num)) {
printf("%d is a prime number.\n", num);
} else {
printf("%d is not a prime number.\n", num);
}
return 0;
}
PHP is a widely used scripting language, primarily for web development. Below are some common PHP programming problems:
Write a function to reverse a given string.
function reverseString($str) {
return strrev($str);
}
$input = "Hello, World!";
echo "Reversed string: " . reverseString($input) . "\n";
Write a function to find the maximum value in a given array.
function findMax($arr) {
return max($arr);
}
$array = [1, 2, 3, 4, 5];
echo "Maximum value: " . findMax($array) . "\n";
By going through the C and PHP programming problem bank and solutions, you can effectively practice coding skills and enhance your problem-solving abilities. Mastering these programming languages will lay a solid foundation for your career in IT. Continuously exploring more programming problems and solutions will help you grow as a developer and improve your technical expertise.