Skip to content

Commit e182115

Browse files
Initial commit
0 parents  commit e182115

Some content is hidden

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

65 files changed

+1308
-0
lines changed

.github/workflows/classroom.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: CI - Run tests
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
repository_dispatch:
7+
8+
permissions:
9+
checks: write
10+
actions: read
11+
contents: read
12+
13+
jobs:
14+
build-and-test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v4
20+
21+
- name: Install dependencies
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y gcc
25+
26+
- name: Run shell test scripts
27+
run: |
28+
chmod +x tests/*.sh
29+
failed=0
30+
31+
for t in \
32+
tests/testq1.sh \
33+
tests/testq2.sh \
34+
tests/testq3.sh \
35+
tests/testq4.sh \
36+
tests/testq5.sh \
37+
tests/testq6.sh \
38+
tests/testq7.sh \
39+
tests/testq8.sh \
40+
tests/testq9.sh \
41+
tests/testq10.sh \
42+
tests/testq11.sh \
43+
tests/testq12.sh \
44+
tests/testq13.sh \
45+
tests/testq14.sh \
46+
tests/testq15.sh \
47+
tests/testq16.sh \
48+
tests/testq17.sh \
49+
tests/testq18.sh \
50+
tests/testq19.sh \
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 \
62+
tests/test_pdf.sh; do
63+
echo "Running $t ..."
64+
if ! $t; then
65+
failed=1 # record failure but continue
66+
fi
67+
echo
68+
done
69+
70+
if [ $failed -ne 0 ]; then
71+
echo "❌ Some tests failed"
72+
exit 1
73+
else
74+
echo "✅ All tests passed"
75+
fi

.gitignore

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[codz]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py.cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# UV
98+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
#uv.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
#poetry.toml
110+
111+
# pdm
112+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115+
#pdm.lock
116+
#pdm.toml
117+
.pdm-python
118+
.pdm-build/
119+
120+
# pixi
121+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122+
#pixi.lock
123+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124+
# in the .venv directory. It is recommended not to include this directory in version control.
125+
.pixi
126+
127+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128+
__pypackages__/
129+
130+
# Celery stuff
131+
celerybeat-schedule
132+
celerybeat.pid
133+
134+
# SageMath parsed files
135+
*.sage.py
136+
137+
# Environments
138+
.env
139+
.envrc
140+
.venv
141+
env/
142+
venv/
143+
ENV/
144+
env.bak/
145+
venv.bak/
146+
147+
# Spyder project settings
148+
.spyderproject
149+
.spyproject
150+
151+
# Rope project settings
152+
.ropeproject
153+
154+
# mkdocs documentation
155+
/site
156+
157+
# mypy
158+
.mypy_cache/
159+
.dmypy.json
160+
dmypy.json
161+
162+
# Pyre type checker
163+
.pyre/
164+
165+
# pytype static type analyzer
166+
.pytype/
167+
168+
# Cython debug symbols
169+
cython_debug/
170+
171+
# PyCharm
172+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174+
# and can be added to the global gitignore or merged into this file. For a more nuclear
175+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
176+
#.idea/
177+
178+
# Abstra
179+
# Abstra is an AI-powered process automation framework.
180+
# Ignore directories containing user credentials, local state, and settings.
181+
# Learn more at https://abstra.io/docs
182+
.abstra/
183+
184+
# Visual Studio Code
185+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
188+
# you could uncomment the following to ignore the entire vscode folder
189+
# .vscode/
190+
191+
# Ruff stuff:
192+
.ruff_cache/
193+
194+
# PyPI configuration file
195+
.pypirc
196+
197+
# Cursor
198+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200+
# refer to https://docs.cursor.com/context/ignore-files
201+
.cursorignore
202+
.cursorindexingignore
203+
204+
# Marimo
205+
marimo/_static/
206+
marimo/_lsp/
207+
__marimo__/

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Assignment 3: Array, Strings and Functions
2+
3+
## Instructions
4+
5+
1. Write code in the corresponding `src/` file for each programming task.
6+
2. Upload a `PDF` containing all answers with output screenshot in the docs/ folder
7+
- You can create a doc and convert it to PDF online.
8+
- Name pdf as `answer.pdf`
9+
- Your first line of pdf should be `Name: Firstname-Lastname`. Eg: Name: Nirajan-Thakuri
10+
1. Do not change file names — tests depend on them.
11+
2. Commit and push your changes to GitHub.
12+
13+
---
14+
15+
## Questions
16+
17+
**Q1.** Write a C program to find the maximum and minimum elements in an array.
18+
19+
**Q2.** Implement a C program to reverse the elements of an array.
20+
21+
**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).
22+
23+
**Q4.** Implement a C program to find the second largest element in an array.
24+
25+
**Q5.** Write a C program to merge two sorted arrays into a single sorted array.
26+
27+
**Q6.** Write a C program to find the length of a string without using the built-in string functions.
28+
29+
**Q7.** Implement a C program to reverse a string.
30+
31+
**Q8.** Write a C program to check if a given string is a palindrome.
32+
33+
**Q9.** Implement a C program to count the occurrence of a specific character in a string.
34+
35+
**Q10.** Write a C program to concatenate two strings without using the built-in string
36+
functions.
37+
38+
**Q11.** Write a function named calculateAverage that takes an array of integers as input and returns the average of the numbers.
39+
40+
**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.
41+
42+
**Q13.** Write a function named findFactorial that takes an integer as input and returns its factorial.
43+
44+
**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.
45+
46+
**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.
47+
48+
**Q16.** Write a function named reverseArray that takes an array of integers as input and reverses the order of the elements in the array.
49+
50+
**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.
51+
52+
**Q18.** Write a function named findPrimeNumbers that takes an integer n as input and prints all prime numbers from 1 to n.
53+
54+
**Q19.** Write a function named calculateFactorialSeries that takes an integer n as input and prints the factorial series up to n.
55+
56+
**Q20.** Write a function named calculateGCD that takes two integers as input and returns their greatest common divisor (GCD).
57+
58+
**Q21.** Write a recursive function named calculateFactorial that takes an integer n as input and returns its factorial.
59+
60+
**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.
61+
62+
**Q23.** Write a recursive function named calculateGCD that takes two integers a and b as input and returns their greatest common divisor (GCD).
63+
64+
**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.
65+
66+
**Q25.** Write a recursive function named calculateSumOfDigits that takes an integer n as input and returns the sum of its digits.
67+
68+
**Q26.** Write a recursive function named reverseString that takes a string as input and returns the reversed string.
69+
70+
**Q27.** Write a recursive function named printTriangle that takes an integer n as input and prints a triangle of asterisks (*) with n rows.
71+
72+
**Q28.** Write a recursive function named calculateBinary that takes an integer n as input and returns its binary representation as a string.
73+
74+
**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.
75+
76+
**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.
77+
78+
---
79+
80+
## Deadline: 23:59, Saturday, 15th Nov, 2025

docs/.gitkeep

Whitespace-only changes.

src/q1.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Write a C program to find the maximum and minimum elements in an array.

src/q10.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Write a C program to concatenate two strings without using the built-in string functions.

src/q11.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Write a function named findFactorial that takes an integer as input and returns its factorial.

src/q14.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

0 commit comments

Comments
 (0)