Introduction to Computer Science YMT113 · Fall 2026 Assoc. Prof. Ferhat Uçar

>_ Lab 2 · Week 3 · Monday, October 5, 2026 · C

C Kickstart

Your first real C programs: three one-line warm-ups (hello, greet, bits), then mario pyramids, a calculator with validated input and cash change-making with a greedy loop. Accepted and autograded on Classroom 50.

week
3 · Mon, Oct 5
due
Fri, Oct 9 · 23:59
points
10 (autograded)
time
90 min + finish at home
files you edit
hello.cgreet.cbits.cmario.ccalculator.ccash.c

Goal

By the end of this lab you have written six small C programs and watched them pass real tests. The first three are warm-ups with one line to change each; the last three you write yourself from the building blocks of the week 3 page: do … while for input, nested for loops, if, casting, and the / and % operators. From this lab on we use Classroom 50: one click gives you a private repository, every push is graded within a minute or two, and your score appears on GitHub.

Steps

1

Join the course organization (once)

⏱ 1 min

You received an email from GitHub: “FiratUniversity-IJDP-SoftEng has invited you to join”. Open it and click Join, or go to github.com/FiratUniversity-IJDP-SoftEng and accept the banner at the top. Make sure you are signed in with the same GitHub account you used for Lab 1.

No email? Check spam, then tell the instructor your GitHub username.

2

Accept Lab 2 on Classroom 50

⏱ 2 min
  1. Click the orange Accept lab lab02 button at the top of this page. Sign in with GitHub if asked and authorize Classroom 50.
  2. Click Accept assignment. A checklist runs for about 20 seconds while your repository is created.
  3. Click Open repository.

You now own a private repository called introduction-to-computer-science-lab02-yourusername. Only you and the instructor can see it.

3

Open it in Codespaces

⏱ 2–3 min the first time

On your repository page: green Code button → Codespaces tab → Create codespace on main.

VS Code opens in your browser. The first start takes a couple of minutes while gcc, make, valgrind and the tests are installed; watch the terminal at the bottom until it shows a prompt ending in $.

4

Look around and run the checks once

⏱ 3 min
FileWhat it is
hello.c, greet.c, bits.cParts A–C, warm-ups: each has a one-line TODO
mario.c, calculator.c, cash.cParts D–F: you write them; the comment at the top of each file is the specification
cs50.h, cs50.cthe CS50 library (get_int, get_string); do not edit
Makefilelets you type make mario instead of the long compiler command
lab02.ipynbplayground notebook, not graded
check.pythe friendly test runner
tests/the tests, one file per part; the autograder runs exactly these

In the terminal:

>_ terminal
$ python3 check.py:| hello.c prints "hello, world"
  expected 'hello, world\n', got 'hello, TODO\n'
...
0/14 checks passed

Everything fails because nothing is done yet. Your job is to turn the list green, part by part.

5

Part A · hello.c

⏱ 3 min

Open hello.c. One word is wrong. Make it print exactly hello, world with a newline, then compile and run:

>_ terminal
$ make hello$ ./hellohello, world

If the compiler complains, read the first error; it names the line.

6

Part B · greet.c

⏱ 5 min

greet.c asks for a name with get_string and stores it in name. Complete the printf so that it prints hello, followed by the name and a newline. %s is the placeholder, and the value goes after the format string, separated by a comma, exactly like hello2.c in the lecture.

>_ terminal
$ make greet$ ./greetWhat's your name? Firat
hello, Firat
7

Part C · bits.c

⏱ 5 min

bits.c asks for a number from 0 to 255 and loops over its 8 bits; bit is already 1 or 0. Replace the two ? so that it prints '1' when bit is 1 and '0' otherwise.

>_ terminal
$ make bits$ ./bitsNumber (0–255): 73
01001001

That is last week’s bit widget, now in C.

8

Part D · mario.c

⏱ 20 min

Write a program that asks for a height from 1 to 8, re-prompting until it gets one, and prints a right-aligned pyramid:

>_ terminal
$ make mario$ ./marioHeight: 4
 #
##
###
####

Plan it before you type. Row 1 has three spaces and one #; row 2 has two spaces and two #; in general row i has height - i spaces and i hashes. So:

  1. A do … while that asks for height until it is between 1 and 8 (lecture: mario7.c).
  2. An outer for over the rows, i from 1 to height.
  3. Inside it, one for that prints height - i spaces, then one for that prints i hashes, then printf("\n").
9

Part E · calculator.c

⏱ 15 min

Read two integers x and y and print five lines: the sum, the difference, the product, the quotient as a real number with two decimals, and the remainder. If y is 0, print the word undefined for the last two lines instead of dividing.

>_ terminal
$ make calculator$ ./calculatorx: 7
y: 2
9
5
14
3.50
1

Two traps from the lecture: x / y with ints truncates, so cast first, (float) x / (float) y; and printf("%.2f\n", z) prints two decimals. Dividing by zero crashes a C program, so the if (y == 0) must come before the division.

10

Part F · cash.c

⏱ 15 min

Ask for an amount of change in cents (re-prompt while it is negative) and print the minimum number of coins using quarters (25), dimes (10), nickels (5) and pennies (1).

>_ terminal
$ make cash$ ./cashChange owed: 41
4

41 = 25 + 10 + 5 + 1. The strategy is greedy: always take the largest coin that still fits. Two ways to write it: a while (cents >= 25) loop per coin, or arithmetic: cents / 25 is how many quarters fit and cents % 25 is what is left. Both are correct; the second is four lines shorter. Try 0, 1 and 99 by hand before you trust the tests.

11

Submit

⏱ 2 min

When python3 check.py shows 14/14 checks passed (or when you have done what you can), push. Every push is graded.

>_ terminal
$ git add -A$ git commit -m "Lab 2"$ git push

Prefer buttons? Source Control icon on the left of VS Code: type a message, click Commit, then Sync Changes.

About two minutes after the push:

  1. On your repository page, look under Releases on the right. The newest release shows your score out of 10 and a table of the six parts.
  2. Or on classroom50.org, open the assignment and click My submission.

Push as often as you like before Friday, October 9, 23:59; the last push before the deadline counts. Pushes up to five days late lose 10% per day.

How to submit

Points: hello 1, greet 1, bits 1, mario 3, calculator 2, cash 2. Each part is graded by its own test file, so a part you did not finish costs only its own points.

Other ways to work and submit

Codespaces is the easiest route, but it is not the only one. You can write your C anywhere and hand it in from the browser. Grading is exactly the same: every change that lands in your repository is graded automatically.

Where you can work

OptionWhat to do
Your own computerInstall a C compiler: macOS xcode-select --install in Terminal; Windows: WSL then sudo apt install gcc make; Linux: sudo apt install gcc make. Download your repository (green Code button → Download ZIP), unzip, and in that folder compile each program with the library: gcc -o mario mario.c cs50.c then ./mario. If make is installed, make mario does the same. For the checks, install Python 3 and pip install pytest, then python3 check.py.
cs50.devOpen cs50.dev. The CS50 library is preinstalled there, so you can create mario.c, paste your code, and run make mario and ./mario exactly as in the lecture. Copy your finished file back into your repository (below).
Google ColabOpen the lab notebook with the Open in Colab button below; a cell that starts with %%writefile mario.c saves your code, and !gcc -o mario mario.c cs50.c && ./mario compiles and runs it. Upload cs50.h and cs50.c from your repository into the Colab session first (folder icon on the left → upload). Programs that ask for input need echo 4 | ./mario instead of typing.
github.devOn your repository page press the . key. A light VS Code opens in the browser for editing and committing (it cannot compile C).

Submit from the browser (no terminal, no git)

When a program is ready in a file on your computer or in another editor, put it into your repository on github.com in one of two ways.

A. Paste into the file

  1. Open your repository introduction-to-computer-science-lab02-yourusername on github.com.
  2. Click mario.c, then the pencil icon ✎ (Edit this file) at the top right of the file.
  3. Select everything (Ctrl + A, or ⌘ + A on a Mac) and paste your complete file.
  4. Click Commit changes…, write a short message such as Lab 2 mario, keep Commit directly to the main branch selected, and click Commit changes.
  5. Do the same for each file you changed.

B. Upload the files

  1. On your repository page click Add file → Upload files.
  2. Drag your .c files from your computer into the box. Files with the same name replace the starter files; that is what you want.
  3. Click Commit changes.

Check your grade the same way. About two minutes after each commit, a new Release with your score appears on the right of your repository page. Every commit counts as a submission, the last one before Friday 23:59 is the one that matters, and you may mix methods (for example, push from Codespaces on Monday and paste a fix from home on Wednesday).

Explore: C in a notebook

lab02.ipynb is not graded. It writes C files, compiles them and runs them cell by cell: types, printf placeholders, the bit loop explained, and integer overflow on purpose. Open it in your codespace (choose the Python kernel) or in Colab with the button below; nothing to install.

Lab 2 · Explore: C in a notebook

Read it here, or open it in Colab: it writes, compiles and runs C right in the browser.

Challenges (optional, not graded)

  1. Mario, two-sided. Print the pyramid with a mirror image and a two-space gap, as in the real game.
  2. Cash in Turkish lira. Coins of 1, 0.50, 0.25, 0.10 and 0.05 lira: read kuruş as an integer and keep greedy working.
  3. Calculator with a menu. Ask which operation the user wants with get_char and if … else if, like agree2.c.

Troubleshooting