11. Find the factorial of a number using iteration. Calculate factorial of 7.

Required Input:

7

Expected Output:

Factorial of 7 is 5040

Code In C

#include int factorial(int n) { // Your code here } int main() { int n = 7; printf("Factorial of %d is %d\n", n, factorial(n)); return 0; }

Output

Click Run Button to view compiled output

12. Check if two strings "listen" and "silent" are anagrams.

Required Input:

listen silent

Expected Output:

Are anagrams: Yes

Code In C

#include #include int areAnagrams(char str1[], char str2[]) { // Your code here } int main() { char str1[] = "listen"; char str2[] = "silent"; printf("Are anagrams: %s\n", areAnagrams(str1, str2) ? "Yes" : "No"); return 0; }

Output

Click Run Button to view compiled output

13. Write a function to merge two sorted arrays {1, 3, 5} and {2, 4, 6} into a single sorted array.

Required Input:

1 3 5
 2 4 6

Expected Output:

1 2 3 4 5 6 

Code In C

#include void mergeArrays(int arr1[], int n1, int arr2[], int n2, int result[]) { // Your code here } int main() { int arr1[] = {1, 3, 5}; int arr2[] = {2, 4, 6}; int result[6]; mergeArrays(arr1, 3, arr2, 3, result); for (int i = 0; i < 6; i++) { printf("%d ", result[i]); } printf("\n"); return 0; }

Output

Click Run Button to view compiled output

14. Find the sum of all even numbers in an array {4, 7, 10, 13, 18}.

Required Input:

4 7 10 13 18

Expected Output:

Sum of even numbers: 32

Code In C

#include int sumEvenNumbers(int arr[], int n) { // Your code here } int main() { int arr[] = {4, 7, 10, 13, 18}; printf("Sum of even numbers: %d\n", sumEvenNumbers(arr, 5)); return 0; }

Output

Click Run Button to view compiled output

15. Write a function to find the transpose of a 2x3 matrix {{1, 2, 3}, {4, 5, 6}}.

Required Input:

Matrix:
 1 2 3
 4 5 6

Expected Output:

1 4 
2 5 
3 6 

Code In C

#include void transposeMatrix(int matrix[2][3], int transposed[3][2]) { // Your code here } int main() { int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}}; int transposed[3][2]; transposeMatrix(matrix, transposed); for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { printf("%d ", transposed[i][j]); } printf("\n"); } return 0; }

Output

Click Run Button to view compiled output

16. Calculate the average of an array {15, 22, 8, 10, 35}.

Required Input:

15 22 8 10 35

Expected Output:

Average: 18.00

Code In C

#include float calculateAverage(int arr[], int n) { // Your code here } int main() { int arr[] = {15, 22, 8, 10, 35}; printf("Average: %.2f\n", calculateAverage(arr, 5)); return 0; }

Output

Click Run Button to view compiled output

17. Check if a character 'A' is a vowel or consonant.

Required Input:

A

Expected Output:

A is a vowel

Code In C

#include void checkVowelConsonant(char ch) { // Your code here } int main() { char ch = 'A'; checkVowelConsonant(ch); return 0; }

Output

Click Run Button to view compiled output

18. Write a function to reverse an integer array {9, 2, 3, 5, 7}.

Required Input:

9 2 3 5 7

Expected Output:

7 5 3 2 9 

Code In C

#include void reverseArray(int arr[], int n) { // Your code here } int main() { int arr[] = {9, 2, 3, 5, 7}; reverseArray(arr, 5); for (int i = 0; i < 5; i++) { printf("%d ", arr[i]); } printf("\n"); return 0; }

Output

Click Run Button to view compiled output

19. Calculate the number of digits in an integer 12345.

Required Input:

12345

Expected Output:

Number of digits: 5

Code In C

#include int countDigits(int num) { // Your code here } int main() { int num = 12345; printf("Number of digits: %d\n", countDigits(num)); return 0; }

Output

Click Run Button to view compiled output

20. Find the largest element in each row of a 2x3 matrix {{3, 5, 1}, {7, 2, 8}}.

Required Input:

Matrix:
 3 5 1
 7 2 8

Expected Output:

Max element in row 1: 5
Max element in row 2: 8

Code In C

#include void maxInRows(int matrix[2][3]) { // Your code here } int main() { int matrix[2][3] = {{3, 5, 1}, {7, 2, 8}}; maxInRows(matrix); return 0; }

Output

Click Run Button to view compiled output

ad vertical

2 of 3