CS 50

Intro to C Programming

Fundamentals of programming in C: variables, control flow, functions, arrays, pointers, and memory. Assignments built real programs from scratch — culminating in a complete terminal-based game.

Homework 3 — Game

Cosmic Crystals

Terminal-based exploration game on a 5×5 grid. Three crystals and three black holes are randomly placed on a hidden board. Navigate with W/A/S/D — collect all crystals before running out of moves or stepping into a black hole. Uses 2D arrays, rand() with time-based seeding, and modular functions for board init, rendering, and collision.

C2D Arraysrand() / srand()FunctionsGame Loop
cosmic_crystals.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define ROWS 5
#define COLS 5
#define CRYSTAL 'C'
#define HOLE    'B'

int main(void) {
    char hidden[ROWS][COLS];   // actual contents: C, B, or .
    char display[ROWS][COLS];  // what the player sees: P or .
    int playerRow = ROWS - 1, playerCol = 0;
    int movesLeft = 15, crystalsCollected = 0;

    srand((unsigned int)time(NULL));
    placeItems(hidden, CRYSTAL, 3);
    placeItems(hidden, HOLE, 3);

    while (movesLeft > 0) {
        printBoard(display);
        // check hidden[newRow][newCol] for CRYSTAL or HOLE
        if (hidden[newRow][newCol] == HOLE) {
            printf("You fell into a black hole. Game over!\n");
            break;
        } else if (hidden[newRow][newCol] == CRYSTAL) {
            printf("Crystal collected! (+1)\n");
            hidden[newRow][newCol] = EMPTY;
        }
    }
}
Homework 1 — Six Programs

Foundational C Programs

Six programs covering core C concepts: math functions, formatted I/O, user input, ASCII art, and loops. Each included a challenge extension applying the same concepts in more complex ways.

printf / scanfmath.hfor loops2D arraysASCII art

Circle Area

Computes area from radius using M_PI. Challenge: reverse-solves radius from a given area and circumference using sqrt().

TicTacShmoe

Prints three winning tic-tac-toe boards with printf and \t. Challenge: uses a 2D char array and nested loops to generate boards dynamically.

Triangle Area

Computes area = 0.5 × base × height. Takes both values on one line using scanf("%f %f", ...).

Miles → Kilometers

Converts user-entered miles to km using factor 1.60934. Tested with 60 mi and 30 mi inputs.

ASCII Initials

Renders "IG" in block-letter ASCII art followed by a framed smiley face, all built from printf strings.

Up It Calculator

Prints double and quadruple of a user's input. Challenge: for loop prints the same output for every number 1–10.

homework1part5.c — ASCII initials
#include<stdio.h>

int main() {
    printf("IIIIIII   GGGGGG \n");
    printf("   I      G      \n");
    printf("   I      G  GGG \n");
    printf("   I      G    G \n");
    printf("IIIIIII   GGGGG  \n");

    printf("      *****      \n");
    printf("    *       *    \n");
    printf("   *  O   O  *   \n");
    printf("   *  \\___/  *   \n");
    printf("      *****      \n");
    return 0;
}
Math 7

Calculus 1

Introduction to differential calculus. Covers limits, continuity, derivatives, and their applications — optimization, related rates, and curve sketching.

Limits & Continuity

  • Definition of a limit
  • One-sided limits
  • Limit laws
  • Squeeze theorem
  • Continuity & discontinuities

Derivatives

  • Definition via difference quotient
  • Power, product, quotient rules
  • Chain rule
  • Implicit differentiation
  • Trig & exponential derivatives

Applications

  • Optimization problems
  • Related rates
  • L'Hôpital's rule
  • Mean Value Theorem
  • Curve sketching
Econ 2

Macroeconomics

Principles of macroeconomics — how economies function at the national level. Covers GDP measurement, inflation, unemployment, fiscal policy, and monetary policy.

Measuring the Economy

  • GDP by income & expenditure
  • Nominal vs. real GDP
  • GDP deflator & CPI
  • Net Domestic Product
  • GNP vs. NNP

Labor & Production

  • Labor productivity
  • Potential GDP
  • Production function
  • Unemployment rate
  • Full employment

Policy & Inflation

  • Fiscal policy (taxes, spending)
  • Monetary policy (interest rates)
  • Four factors of production
  • Inflation measurement
  • Market equilibrium