If you have any query feel free to chat us!
Happy Coding! Happy Learning!
Copy code
int max(int a, int b) {
if (a > b) {
return a;
} else {
return b;
}
}
Copy code
int sumArray(int* arr, int size) {
int sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
}
return sum;
}
Copy code
int countVowels(char* str) {
int count = 0;
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' ||
str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U') {
count++;
}
}
return count;
}
Copy code
int factorial(int n) {
if (n == 0) {
return 1;
}
return n * factorial(n - 1);
}
Copy code
void bubbleSort(int* arr, int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
Please note that these are just sample solutions to the problems, and there are many ways to solve a problem in C. Also, these problems are not meant to be difficult, the goal is to give you an idea of how functions work in C and how they can be used to solve problems.
Comments: 0