|
1 | | -# Assignment 2: Conditional and loops |
| 1 | +# Assignment 3: Array, Strings and Functions |
2 | 2 |
|
3 | 3 | ## Instructions |
4 | 4 |
|
|
10 | 10 |
|
11 | 11 | ## Questions |
12 | 12 |
|
13 | | -**Q1.** Write a C program that takes an integer input from the user and determines if it is positive, negative, or zero. |
| 13 | +**Q1.** Write a C program to find the maximum and minimum elements in an array. |
14 | 14 |
|
15 | | -**Q2.** Write a C program that prompts the user for their age and determines if they are eligible to vote (consider the legal voting age in your country). |
| 15 | +**Q2.** Implement a C program to reverse the elements of an array. |
16 | 16 |
|
17 | | -**Q3.** Write a C program that calculates the absolute value of a given number without using the built-in absolute value function. |
| 17 | +**Q3.** Write a C program to sort an array of integers in ascending order using a sorting algorithm of your choice (e.g., bubble sort, selection sort, insertion sort). |
18 | 18 |
|
19 | | -**Q4.** Write a C program that prints all even numbers between 1 and 100 using a for loop. |
| 19 | +**Q4.** Implement a C program to find the second largest element in an array. |
20 | 20 |
|
21 | | -**Q5.** Write a C program that prompts the user for a positive integer and calculates the factorial of that number using a while loop. |
| 21 | +**Q5.** Write a C program to merge two sorted arrays into a single sorted array. |
22 | 22 |
|
23 | | -**Q6.** Write a C program that prompts the user for a number and prints its multiplication table up to 10 using a do-while loop. |
| 23 | +**Q6.** Write a C program to find the length of a string without using the built-in string functions. |
24 | 24 |
|
25 | | -**Q7.** Write a C program that prints a pattern of asterisks. |
| 25 | +**Q7.** Implement a C program to reverse a string. |
26 | 26 |
|
27 | | -``` |
28 | | - * |
29 | | - ** |
30 | | - *** |
31 | | - **** |
32 | | - ***** |
33 | | - **** |
34 | | - *** |
35 | | - ** |
36 | | - * |
37 | | -``` |
| 27 | +**Q8.** Write a C program to check if a given string is a palindrome. |
38 | 28 |
|
39 | | -**Q8.** Write a C program that prints a pattern of asterisks. |
| 29 | +**Q9.** Implement a C program to count the occurrence of a specific character in a string. |
40 | 30 |
|
41 | | -``` |
42 | | - * |
43 | | - ** |
44 | | - *** |
45 | | - **** |
46 | | - ***** |
47 | | -``` |
| 31 | +**Q10.** Write a C program to concatenate two strings without using the built-in string |
| 32 | +functions. |
48 | 33 |
|
49 | | -**Q9.** Write a C program that prints a pattern of asterisks. |
| 34 | +**Q11.** Write a function named calculateAverage that takes an array of integers as input and returns the average of the numbers. |
50 | 35 |
|
51 | | -``` |
52 | | - ***** |
53 | | - **** |
54 | | - *** |
55 | | - ** |
56 | | - * |
57 | | -``` |
| 36 | +**Q12.** Write a function named isPalindrome that takes a string as input and returns 1 if it is a palindrome (reads the same forwards and backwards), and 0 otherwise. |
58 | 37 |
|
59 | | -**Q10.** Write a C program that prints a pattern of asterisks. |
| 38 | +**Q13.** Write a function named findFactorial that takes an integer as input and returns its factorial. |
60 | 39 |
|
61 | | -``` |
62 | | - * |
63 | | - *** |
64 | | - ***** |
65 | | -``` |
| 40 | +**Q14.** Write a function named convertTemperature that takes a temperature value in Celsius and converts it to Fahrenheit. The function should return the converted temperature. |
66 | 41 |
|
67 | | -**Q11.** Write a C program that prints a pattern of asterisks. |
| 42 | +**Q15.** Write a function named countOccurrences that takes a string and a character as input and returns the number of times the character appears in the string. |
68 | 43 |
|
69 | | -``` |
70 | | - ***** |
71 | | - *** |
72 | | - * |
73 | | -``` |
| 44 | +**Q16.** Write a function named reverseArray that takes an array of integers as input and reverses the order of the elements in the array. |
74 | 45 |
|
75 | | -**Q12.** Write a C program that prints all numbers from 1 to 100 using a for loop. |
| 46 | +**Q17.** Write a function named calculatePower that takes two integers, base and exponent, as input and returns the result of raising the base to the exponent. |
76 | 47 |
|
77 | | -**Q13.** Write a C program that calculates the sum of all even numbers from 1 to 50 using a while loop. |
| 48 | +**Q18.** Write a function named findPrimeNumbers that takes an integer n as input and prints all prime numbers from 1 to n. |
78 | 49 |
|
79 | | -**Q14.** Write a C program that prompts the user for a positive integer and prints all the factors of that number using a for loop. |
| 50 | +**Q19.** Write a function named calculateFactorialSeries that takes an integer n as input and prints the factorial series up to n. |
80 | 51 |
|
81 | | -**Q15.** Write a C program that prompts the user for a positive integer and checks if it is a prime number using a while loop. |
| 52 | +**Q20.** Write a function named calculateGCD that takes two integers as input and returns their greatest common divisor (GCD). |
82 | 53 |
|
83 | | -**Q16.** Write a C program that calculates the factorial of a given number using a do-while loop. |
| 54 | +**Q21.** Write a recursive function named calculateFactorial that takes an integer n as input and returns its factorial. |
84 | 55 |
|
85 | | -**Q17.** Write a C program that prompts the user for a positive integer and prints a countdown from that number to 1 using a for loop. |
| 56 | +**Q22.** Write a recursive function named calculateFibonacci that takes an integer n as input and returns the nth Fibonacci number. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding numbers. |
86 | 57 |
|
87 | | -**Q18.** Write a C program that prompts the user for a positive integer and prints the multiplication table for that number up to 10 using a while loop. |
| 58 | +**Q23.** Write a recursive function named calculateGCD that takes two integers a and b as input and returns their greatest common divisor (GCD). |
88 | 59 |
|
89 | | -**Q19.** Write a C program that prompts the user for a positive integer and prints a pattern of asterisks (*) in a square shape using nested loops. |
| 60 | +**Q24.** Write a recursive function named calculatePower that takes two integers base and exponent as input and returns the result of raising the base to the exponent. |
90 | 61 |
|
91 | | -Example: User’s Input = 2, then pattern to print will be: |
| 62 | +**Q25.** Write a recursive function named calculateSumOfDigits that takes an integer n as input and returns the sum of its digits. |
92 | 63 |
|
93 | | -``` |
94 | | - * * |
95 | | - * * |
96 | | -``` |
| 64 | +**Q26.** Write a recursive function named reverseString that takes a string as input and returns the reversed string. |
97 | 65 |
|
98 | | -**Q20.** Write a C program that prompts the user for a number between 1 and 7 and prints the corresponding day of the week using a switch-case statement. |
| 66 | +**Q27.** Write a recursive function named printTriangle that takes an integer n as input and prints a triangle of asterisks (*) with n rows. |
| 67 | + |
| 68 | +**Q28.** Write a recursive function named calculateBinary that takes an integer n as input and returns its binary representation as a string. |
| 69 | + |
| 70 | +**Q29.** Write a recursive function named isPalindrome that takes a string as input and returns 1 if it is a palindrome (reads the same forwards and backwards), and 0 otherwise. |
| 71 | + |
| 72 | +**Q30.** Write a recursive function named countOccurrences that takes a string and a character as input and returns the number of times the character appears in the string. |
99 | 73 |
|
100 | 74 | --- |
101 | 75 |
|
102 | | -## Deadline: 23:59, Saturday, 6th Sep, 2025 |
| 76 | +## Deadline: 23:59, Saturday, 15th Nov, 2025 |
0 commit comments