Skip to content

Commit bb35be6

Browse files
authored
Initial commit
0 parents  commit bb35be6

Some content is hidden

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

43 files changed

+925
-0
lines changed

.github/workflows/classroom.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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; do
52+
echo "Running $t ..."
53+
if ! $t; then
54+
failed=1 # record failure but continue
55+
fi
56+
echo
57+
done
58+
59+
if [ $failed -ne 0 ]; then
60+
echo "❌ Some tests failed"
61+
exit 1
62+
else
63+
echo "✅ All tests passed"
64+
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: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Assignment 2: Conditional and loops
2+
3+
## Instructions
4+
5+
1. Write code in the corresponding `src/` file for each programming task.
6+
2. Do not change file names — tests depend on them.
7+
3. Commit and push your changes to GitHub.
8+
9+
---
10+
11+
## Questions
12+
13+
**Q1.** Write a C program that takes an integer input from the user and determines if it is positive, negative, or zero.
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).
16+
17+
**Q3.** Write a C program that calculates the absolute value of a given number without using the built-in absolute value function.
18+
19+
**Q4.** Write a C program that prints all even numbers between 1 and 100 using a for loop.
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.
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.
24+
25+
**Q7.** Write a C program that prints a pattern of asterisks.
26+
27+
```
28+
*
29+
**
30+
***
31+
****
32+
*****
33+
****
34+
***
35+
**
36+
*
37+
```
38+
39+
**Q8.** Write a C program that prints a pattern of asterisks.
40+
41+
```
42+
*
43+
**
44+
***
45+
****
46+
*****
47+
```
48+
49+
**Q9.** Write a C program that prints a pattern of asterisks.
50+
51+
```
52+
*****
53+
****
54+
***
55+
**
56+
*
57+
```
58+
59+
**Q10.** Write a C program that prints a pattern of asterisks.
60+
61+
```
62+
*
63+
***
64+
*****
65+
```
66+
67+
**Q11.** Write a C program that prints a pattern of asterisks.
68+
69+
```
70+
*****
71+
***
72+
*
73+
```
74+
75+
**Q12.** Write a C program that prints all numbers from 1 to 100 using a for loop.
76+
77+
**Q13.** Write a C program that calculates the sum of all even numbers from 1 to 50 using a while loop.
78+
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.
80+
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.
82+
83+
**Q16.** Write a C program that calculates the factorial of a given number using a do-while loop.
84+
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.
86+
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.
88+
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.
90+
91+
Example: User’s Input = 2, then pattern to print will be:
92+
93+
```
94+
* *
95+
* *
96+
```
97+
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.
99+
100+
---
101+
102+
## Deadline: 23:59, Saturday, 6th Sep, 2025

src/q1.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
*/

src/q10.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* Write a C program that prints a pattern of asterisks.
2+
*
3+
***
4+
*****
5+
*/

src/q11.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* Write a C program that prints a pattern of asterisks.
2+
*****
3+
***
4+
*
5+
*/

0 commit comments

Comments
 (0)