# Introduction to Programming in C

<figure><img src="/files/nO6nsL3HzIIttc0eS5wD" alt=""><figcaption></figcaption></figure>

## Course Description

An intensive course designed to develop logic and programming skills through immersion in the fundamentals of C. Programming projects involving mathematical problems and word games challenge students to develop their logical reasoning, systematic thinking, and problem-solving skills. Students learn the structure and features of a fundamental programming language as they implement solutions in C. In addition to teaching programming techniques, the course will cover an overview of fundamental computing concepts such as data structures, library design, and memory management.


# session1.c

```c
#include <stdio.h>

int main() {
    printf("Session 1\n");
    // integer variable


    // floating point variable
 

    // double precision variable
    double number = 3.14159265358979323846;

    // character variable


    // mixing things up!
    
    
    // operator examples


    // division examples


    // increment operators


    // scanf example



    return 0;
}
```


# session2.c

```c
#include <stdio.h>

int main() {
    printf("Session 2\n");

    // Example 1


    // Example 2


    // Example 3
  

    // Example 4
    

    // Example 5
    

    // Example 6
    

    // Example 7
    

    // Example 8
    

    // Example 9
    

    // Example 10
    

    // Example 11
    
    

    return 0;
}

```


# session3.c

```c
#include <stdio.h>

int main() {
    printf("Session 3\n");

    // Menu



    // get choice from user



    // switch choices



    return 0;
}
```


# veggies.c

```c
#include <stdio.h>

int main() {
     // Menu
     printf("Menu\n");
     printf("1 - apple\n");
     printf("2 - banana\n");
     printf("3 - cherry\n");
     printf("4 - asparagus\n");
     printf("5 - broccoli\n");
     printf("6 - carrot\n");

     // get choice from user
     printf("Choice: ");
     int choice;
     scanf("%d", &choice);

     // rewrite code below using switch
     if (choice == 1) {
         printf("fruit\n");
         printf("sugary\n");
         printf("yummy\n");
     } else if (choice == 2) {
         printf("fruit\n");
         printf("sugary\n");
         printf("yummy\n");
     } else if (choice == 3) {
         printf("fruit\n");
         printf("sugary\n");
         printf("yummy\n");
     } else if (choice == 4) {
         printf("veggie\n");
         printf("healthy\n");
         printf("green\n");
     } else if (choice == 5) {
         printf("veggie\n");
         printf("healthy\n");
         printf("green\n");
    } else if (choice == 6) {
         printf("veggie\n");
         printf("healthy\n");
         printf("orange\n");
    } else {
         printf("Invalid\n");
    }
}
```


# session4.c

```c
#include <stdio.h>

// Example 1 Function Definition


// Example 2 Function Definition


// Example 3 Function Definition


// Example 4 Function Definition


// Example 5 Function Definition


// Example 6 Function Definition


// Example 7 Function Definition


// Example 8 Function Definition


// Example 9 Function Definition


// Example 10 Function Definition


// Main Function
int main() {

    // Menu
    printf("Menu\n");
    printf("1 - Example 1\n");
    printf("2 - Example 2\n");

    // get choice from user
    printf("Choice: ");
    int choice;
    scanf("%d", &choice);

    // switch choices
    switch (choice) {

        default:
            printf("Invalid input\n");
    }
}

```


# session5.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Example 1 Function Definition


// Example 2 Function Definition


// Example 3 Function Definition


// Example 4 Function Definition


// Example 5 Function Definition



// Main Function
int main()
{
    printf("Session 5\n");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 to Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
 
                break;
            case 2:
 
                break;
            case 3:

                break;
            case 4:

                break;
            case 5:

                break;
        }
    }
    while (choice != -1);
}
```


# session5p.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Problem 1 Function Definition



// Main Function
int main()
{
    printf("Session 5 Problems");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Problem 1\n");
        printf("2 - Problem 2\n");
        printf("-1 to Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
 
                break;
            case 2:
 
                break;
            case 3:

                break;
            case 4:

                break;
            case 5:

                break;
        }
    }
    while (choice != -1);
}
```


# session6.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Example 1 Function Definition


// Example 2 Function Definition


// Example 3 Function Definition


// Example 4 Function Definition


// Example 5 Function Definition


// Example 6 Function Definition


// Example 7 Function Definition


// Example 8 Function Definition


// Example 9 Function Definition



// Main Function
int main()
{
    printf("Session 9\n");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 - Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
   
                break;
            case 2:
               
                break;
            case 3:
                
                break;
            case 4:
                
                break;
            case 5:
                
                break;
            case 6:
                
                break;
            case 7:
                
                break;
            case 8:
                
                break;
            case 9:
                
                break;
        }
    }
    while (choice != -1);
}
```


# session6p.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Problem Functions



// Main Function
int main()
{
    printf("Session 9\n");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 - Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
   
                break;
            case 2:
               
                break;
            case 3:
                
                break;
            case 4:
                
                break;
            case 5:
                
                break;
            case 6:
                
                break;
            case 7:
                
                break;
            case 8:
                
                break;
            case 9:
                
                break;
        }
    }
    while (choice != -1);
}
```


# session7.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// Example 1 Function Definition


// Example 2 Function Definition


// Example 3 Function Definition


// Example 4 Function Definition

    
// Example 5 Function Definition


// Main Function
int main()
{
    printf("Session 7\n");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 - Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
                
                break;
            case 2:
                
                break;
            case 3:
                
                break;
            case 4:
                
                break;
            case 5:
                
                break;
         
        }
    }
    while (choice != -1);
}
```


# session7p.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// Problem 1 Function Definition


// Main Function
int main()
{
    printf("Session 7 Problems");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 - Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
                
                break;
            case 2:
                
                break;
            case 3:
                
                break;
            case 4:
                
                break;
            case 5:
                
                break;
         
        }
    }
    while (choice != -1);
}
```


# tictactoe.c

```c
#include <stdio.h>

#define BOARD_SIZE 3

// Function to initialize the Tic Tac Toe board with empty spaces
void initializeBoard(char board[BOARD_SIZE][BOARD_SIZE]) {
    for (int i = 0; i < BOARD_SIZE; i++) {
        for (int j = 0; j < BOARD_SIZE; j++) {
            board[i][j] = ' ';
        }
    }
}

// Function to display the Tic Tac Toe board
void displayBoard(char board[BOARD_SIZE][BOARD_SIZE]) {
    printf("\n");
    for (int i = 0; i < BOARD_SIZE; i++) {
        for (int j = 0; j < BOARD_SIZE; j++) {
            printf(" %c ", board[i][j]);
            if (j < BOARD_SIZE - 1) {
                printf("|");
            }
        }
        printf("\n");
        if (i < BOARD_SIZE - 1) {
            printf("---+---+---\n");
        }
    }
    printf("\n");
}

// Function to check if a player has won
// if there is a winning condition, return 1
int checkWin(char board[BOARD_SIZE][BOARD_SIZE], char player) {
    
    // Check rows
    
    
    // Check columns
    
    
    // Check diagonals
    
    
    return 0;
}

// Function to check if the board is full (draw)
int checkDraw(char board[BOARD_SIZE][BOARD_SIZE]) {
    for (int i = 0; i < BOARD_SIZE; i++) {
        for (int j = 0; j < BOARD_SIZE; j++) {
            if (board[i][j] == ' ') {
                return 0; // There's an empty space, the game is not a draw yet.
            }
        }
    }
    return 1; // The board is full, it's a draw.
}

int main() {
    char board[BOARD_SIZE][BOARD_SIZE];
    char player1 = 'X';
    char player2 = 'O';
    int currentPlayer = 1;
    int row, col;
    int moves = 0;

    initializeBoard(board);

    printf("Tic Tac Toe\n");
    printf("Player 1: X | Player 2: O\n");
    displayBoard(board);

    while (1) {
        printf("Player %d, enter row (0-2) and column (0-2) separated by a space: ", currentPlayer);

        // Get the player's move
        if (scanf("%d %d", &row, &col) != 2 || row < 0 || row >= BOARD_SIZE || col < 0 || col >= BOARD_SIZE) {
            printf("Invalid input. Please try again.\n");
            while (getchar() != '\n'); // Clear input buffer
            continue;
        }

        // Check if the selected cell is empty
        if (board[row][col] != ' ') {
            printf("That cell is already taken. Please try again.\n");
            continue;
        }

        // Make the move for the current player
        board[row][col] = (currentPlayer == 1) ? player1 : player2;
        displayBoard(board);

        // Check if the current player has won
        if (checkWin(board, (currentPlayer == 1) ? player1 : player2)) {
            printf("Player %d wins!\n", currentPlayer);
            break;
        }

        // Check if the game is a draw
        if (checkDraw(board)) {
            printf("It's a draw!\n");
            break;
        }

        // Switch to the other player for the next turn
        currentPlayer = (currentPlayer == 1) ? 2 : 1;
        moves++;
    }

    return 0;
}

```


# session8.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// Example 1 Function Definition


// Example 2 Function Definition


// Example 3 Function Definition


// Example 4 Function Definition


// Example 5 Function Definition


// Example 6 Function Definition


// Example 7 Function Definition


// Example 8 Function Definition


// Example 9 Function Definition


// Main Function
int main()
{
    printf("Session 8\n");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 - Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
                
                break;
            case 2:
                
                break;
            case 3:
                
                break;
            case 4:
                
                break;
            case 5:
                
                break;
            case 6:
                
                break;
            case 7:
                
                break;
            case 8:
                
                break;
            case 9:
                
                break;         
        }
    }
    while (choice != -1);
}
```


# session8p.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// Problem 1 Function Definition


// Main Function
int main()
{
    printf("Session 8 Problems");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 - Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
                
                break;
            case 2:
                
                break;
            case 3:
                
                break;
            case 4:
                
                break;
            case 5:
                
                break;
         
        }
    }
    while (choice != -1);
}
```


# session9.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// Example 1 Function Definition


// Example 2 Function Definition


// Example 3 Function Definition


// Example 4 Function Definition


// Example 5 Function Definition


// Example 6 Function Definition


// Example 7 Function Definition


// Example 8 Function Definition


// Example 9 Function Definition


// Main Function
int main()
{
    printf("Session 9\n");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 - Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
                
                break;
            case 2:
                
                break;
            case 3:
                
                break;
            case 4:
                
                break;
            case 5:
                
                break;
            case 6:
                
                break;
            case 7:
                
                break;
            case 8:
                
                break;
            case 9:
                
                break;
        }
    }
    while (choice != -1);
}
```


# session9p.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// Problem 1 Function Definition


// Main Function
int main()
{
    printf("Session 9 Problems");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 - Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
                
                break;
            case 2:
                
                break;
            case 3:
                
                break;
            case 4:
                
                break;
            case 5:
                
                break;
         
        }
    }
    while (choice != -1);
}
```


# data3.txt

```
88
82
79
86
84
82
86
84
84
86
```


# problem4.txt

```
89
92
85
100
76
82
95
88
93
90
```


# problem5.txt

```
39538223
29145505
21538187
20215751
13011844
12822739
11799448
10725274
10453948
10084442
9294493
9197590
7705281
7243577
6709356
6177224
6175940
5897473
5760946
5118425
4659690
4509342
4390799
4274944
3608298
3563077
3310774
3108462
2978271
2954839
21477737
1953039
1787065
1773973
1459486
1363582
1356127
1085407
1052471
1042301
989415
974563
912500
886773
769361
739773
724153
690432
643503
628061

```


# problem6.txt

```
1
7
10
4
2
9
3
6
8
5
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
2
7
5
3
8
1
6
9
10
4
6
3
1
5
10
8
9
2
7
4

```


# hello.txt

```
Hello, World!
```


# sentences.txt

```
The quick brown fox jumps over the lazy dog.
Jack and Jill went up the hill.
Peter Piper picked a peck of pickled peppers.
She sells seashells by the seashore.
How much wood would a woodchuck chuck if a woodchuck could chuck wood?
Mary had a little lamb whose fleece was white as snow.
Twinkle, twinkle, little star, how I wonder what you are.
Old MacDonald had a farm, E-I-E-I-O.
Humpty Dumpty sat on a wall.
It's raining, it's pouring; the old man is snoring.
```


# people.csv

```csv
Name,Age,College
Teddi,17,Columbia
Devin,16,Stanford
Jada,18,Rutgers

```


# students.csv

```csv
Name,birthyear,favorite food,robux
Abigail,2007,chocolate,0
Luke,2006,pasta,0
Eunseo (Grace),2008,bulgogi,0
Nate,2009,pasta,2
Samuel (Sam),2007,apples,1
Yueqi (Rachel),2005,ice cream,0
Anxu (Liam),2005,apples,1
Stephen,2007,egg,0
Amanda,2006,ceviche,0
```


# powerball.csv

```
Draw Date,Winning Numbers,Multiplier
6/10/23,21 32 42 46 50 04,3
6/12/23,02 03 16 23 68 07,2
6/14/23,03 20 36 42 64 04,2
6/17/23,02 12 45 61 64 26,2
6/19/23,36 39 52 57 69 01,3
6/21/23,05 11 33 35 63 14,2
6/24/23,02 38 44 50 62 19,3
6/26/23,06 28 39 43 54 12,4
6/28/23,19 25 34 57 68 04,5
7/1/23,04 17 35 49 61 08,2
7/3/23,15 26 31 38 61 03,3
7/5/23,17 24 48 62 68 23,2
7/8/23,07 23 24 32 43 18,2
7/10/23,02 24 34 53 58 13,2
7/12/23,23 35 45 66 67 20,3
7/15/23,02 09 43 55 57 18,2
7/17/23,05 08 09 17 41 21,4
7/19/23,07 10 11 13 24 24,2
7/22/23,25 27 36 37 63 07,2
7/24/23,03 04 12 28 49 25,2
7/26/23,03 16 40 48 60 14,2
```


# session10.c

```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// Example 1 Function Definition


// Example 2 Function Definition


/*** Beginnning of Linked List Code *****/


/*** End of Linked List Code *****/


/*** Beginnning of Doubly Linked List Code *****/


/*** End of Doubly Linked List Code *****/

// Main Function
int main()
{
    printf("Session 8\n");
    int choice;
    do
    {
        // Menu
        printf("Menu\n");
        printf("1 - Example 1\n");
        printf("2 - Example 2\n");
        printf("-1 - Quit\n");
        // get choice from user
        printf("Choice: ");
        scanf("%d", &choice);
        // switch choices
        switch (choice)
        {
            case 1:
                
                break;
            case 2:
                
                break;
            case 3:
                
                break;
            case 4:
                
                break;
        }
    }
    while (choice != -1);
}
```


# Linked List Code

```c
// Define the structure of a node
struct Node {
    int data;
    struct Node* next;
};

// Function to create a new node
struct Node* createNode(int data) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    if (newNode != NULL) {
        newNode->data = data;
        newNode->next = NULL;
    }
    return newNode;
}

// Function to insert a new node at the beginning of the linked list
void insertAtBeginning(struct Node** head, int data) {
    struct Node* newNode = createNode(data);
    if (newNode != NULL) {
        newNode->next = *head;
        *head = newNode;
    }
}

// Function to insert a new node at the end of the linked list
void insertAtEnd(struct Node** head, int data) {
    struct Node* newNode = createNode(data);
    if (newNode != NULL) {
        if (*head == NULL) {
            *head = newNode;
        } else {
            struct Node* temp = *head;
            while (temp->next != NULL) {
                temp = temp->next;
            }
            temp->next = newNode;
        }
    }
}

// Function to display the elements of the linked list
void displayLinkedList(struct Node* head) {
    struct Node* temp = head;
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;
    }
    printf("\n");
}

// Function to free the memory used by the linked list
void freeLinkedList(struct Node* head) {
    struct Node* temp;
    while (head != NULL) {
        temp = head;
        head = head->next;
        free(temp);
    }
}
```


# Double Linked List Code

```c
struct DoubleNode {
    int data;
    struct DoubleNode* prev;
    struct DoubleNode* next;
};

// Function to create a new double node
struct DoubleNode* createDoubleNode(int data) {
    struct DoubleNode* newNode = (struct DoubleNode*)malloc(sizeof(struct DoubleNode));
    if (newNode != NULL) {
        newNode->data = data;
        newNode->prev = NULL;
        newNode->next = NULL;
    }
    return newNode;
}

// Function to insert a new double node at the beginning of the list
void insertDoubleAtBeginning(struct DoubleNode** head, int data) {
    struct DoubleNode* newNode = createDoubleNode(data);
    if (newNode != NULL) {
        if (*head != NULL) {
            (*head)->prev = newNode;
            newNode->next = *head;
        }
        *head = newNode;
    }
}

// Function to insert a new double node at the end of the list
void insertDoubleAtEnd(struct DoubleNode** head, int data) {
    struct DoubleNode* newNode = createDoubleNode(data);
    if (newNode != NULL) {
        if (*head == NULL) {
            *head = newNode;
        } else {
            struct DoubleNode* temp = *head;
            while (temp->next != NULL) {
                temp = temp->next;
            }
            temp->next = newNode;
            newNode->prev = temp;
        }
    }
}

// Function to display the elements of the double linked list
void displayDoubleList(struct DoubleNode* head) {
    printf("Doubly Linked List: ");
    struct DoubleNode* temp = head;
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;
    }
    printf("\n");
}

// Function to free the memory used by the double linked list
void freeDoubleList(struct DoubleNode* head) {
    struct DoubleNode* temp;
    while (head != NULL) {
        temp = head;
        head = head->next;
        free(temp);
    }
}

```


