Skip to content

Commit 17d1f68

Browse files
committed
assignment 3
1 parent bb35be6 commit 17d1f68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1419
-521
lines changed

.github/workflows/classroom.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ jobs:
4848
tests/testq17.sh \
4949
tests/testq18.sh \
5050
tests/testq19.sh \
51-
tests/testq20.sh; do
51+
tests/testq20.sh \
52+
tests/testq21.sh \
53+
tests/testq22.sh \
54+
tests/testq23.sh \
55+
tests/testq24.sh \
56+
tests/testq25.sh \
57+
tests/testq26.sh \
58+
tests/testq27.sh \
59+
tests/testq28.sh \
60+
tests/testq29.sh \
61+
tests/testq30.sh; do
5262
echo "Running $t ..."
5363
if ! $t; then
5464
failed=1 # record failure but continue

README.md

Lines changed: 36 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Assignment 2: Conditional and loops
1+
# Assignment 3: Array, Strings and Functions
22

33
## Instructions
44

@@ -10,93 +10,67 @@
1010

1111
## Questions
1212

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.
1414

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.
1616

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).
1818

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.
2020

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.
2222

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.
2424

25-
**Q7.** Write a C program that prints a pattern of asterisks.
25+
**Q7.** Implement a C program to reverse a string.
2626

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.
3828

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.
4030

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.
4833

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.
5035

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.
5837

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.
6039

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.
6641

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.
6843

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.
7445

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.
7647

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.
7849

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.
8051

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).
8253

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.
8455

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.
8657

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).
8859

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.
9061

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.
9263

93-
```
94-
* *
95-
* *
96-
```
64+
**Q26.** Write a recursive function named reverseString that takes a string as input and returns the reversed string.
9765

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.
9973

10074
---
10175

102-
## Deadline: 23:59, Saturday, 6th Sep, 2025
76+
## Deadline: 23:59, Saturday, 15th Nov, 2025

src/q1.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
/* Write a C program that takes an integer input from the user and determines if it is positive, negative, or zero.
2-
Expected Output:
3-
If n > 0, print Positive (case-insensitive, extra messages allowed).
4-
If n < 0, print Negative (case-insensitive, extra messages allowed).
5-
If n == 0, print Zero (case-insensitive, extra messages allowed).
6-
*/
1+
// Write a C program to find the maximum and minimum elements in an array.

src/q10.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
/* Write a C program that prints a pattern of asterisks.
2-
*
3-
***
4-
*****
5-
*/
1+
// Write a C program to concatenate two strings without using the built-in string functions.

src/q11.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
/* Write a C program that prints a pattern of asterisks.
2-
*****
3-
***
4-
*
5-
*/
1+
// Write a function named calculateAverage that takes an array of integers as input and returns the average of the numbers.

src/q12.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// Write a C program that prints all numbers from 1 to 100 using a for loop.
1+
// 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.

src/q13.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// Write a C program that calculates the sum of all even numbers from 1 to 50 using a while loop.
1+
// Write a function named findFactorial that takes an integer as input and returns its factorial.

src/q14.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// Write a C program that prompts the user for a positive integer and prints all the factors of that number using a for loop.
1+
// Write a function named convertTemperature that takes a temperature value in Celsius and converts it to Fahrenheit. The function should return the converted temperature.

src/q15.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// Write a C program that prompts the user for a positive integer and checks if it is a prime number using a while loop.
1+
// 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.

src/q16.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// Write a C program that calculates the factorial of a given number using a do-while loop.
1+
// Write a function named reverseArray that takes an array of integers as input and reverses the order of the elements in the array.

0 commit comments

Comments
 (0)