C Find my level

Find my level

About ten short C problems from across the course, starting in the middle. Each answer decides where the next one comes from, so they get easier or harder as you go. Solve what you can. If something is new to you, say so and move on.

There is no clock, no hints and no solutions. It changes nothing in your progress until you choose a start at the end.

    problem.c to run
    #include <stdio.h>
    
    int main(void) {
        // print the message here
        return 0;
    }
    
    problem.c to run
    #include <stdio.h>
    
    int main(void) {
        printf("I typed this.");
        return 0;
    }
    
    problem.c to run
    #include <stdio.h>
    
    int main(void) {
        int lives = 3
        int coins = 120;
        printf("lives %d, coins %d\n", lives, coins);
        return 0;
    }
    
    problem.c to run
    int main(void) {
        int level = 4;
        printf("Level %d\n", level);
        return 0;
    }
    
    problem.c
    #include <stdio.h>
    
    int main(void) {
        int slices = 7;
        int people = 2;
        double share = slices / people;
        printf("%.1f\n", share);
        printf("%.1f\n", (double)slices / people);
        printf("%d\n", -slices / people);
        printf("%d\n", (int)2.99);
        return 0;
    }
    
    problem.c to run
    #include <stdio.h>
    
    int main(void) {
        printf("char: %zu\n", sizeof(char));
        return 0;
    }
    
    problem.c to run
    #include <stdio.h>
    
    int main(void) {
        int s;
        for (int i = 0; i < 3; i++) {
            scanf("%d", &s);
            if (s = 100) {
                printf("%d: gold\n", s);
            } else {
                printf("%d: keep going\n", s);
            }
        }
        return 0;
    }
    
    problem.c to run
    #include <stdio.h>
    
    int main(void) {
        for (int i = 1; i <= 15; i++) {
            printf("%d\n", i);
        }
        return 0;
    }
    
    problem.c
    #include <stdio.h>
    
    int level_up(int level) {
        level = level + 1;
        return level * 10;
    }
    
    int split_loot(double gold) {
        return gold / 2;
    }
    
    void join_party(int size) {
        if (size >= 4) {
            printf("party full\n");
            return;
        }
        printf("joined, party of %d\n", size + 1);
    }
    
    int main(void) {
        int level = 3;
        int reward = level_up(level);
        printf("%d %d\n", level, reward);
        printf("%d\n", split_loot(7.0));
        join_party(2);
        join_party(4);
        return 0;
    }
    
    problem.c to run
    #include <stdio.h>
    
    int add_combo_bonus(int score, int combo) {
        if (combo >= 10) {
            score = score + combo * 5;
        }
        return score;
    }
    
    int main(void) {
        int score = 200;
        add_combo_bonus(score, 12);
        printf("after a 12-hit combo: %d\n", score);
        add_combo_bonus(score, 3);
        printf("after a 3-hit combo: %d\n", score);
        return 0;
    }
    
    problem.c to run
    #include <stdio.h>
    
    int main(void) {
        unsigned char fuel = 250;
        // add 10, then print
        printf("%u\n", fuel);
        return 0;
    }
    
    problem.c to run
    #include <stdio.h>
    
    int main(void) {
        printf("%d = %d\n", 10, 10);
        return 0;
    }
    
    problem.c
    #include <stdio.h>
    
    int main(void) {
        unsigned char hp = 3;
        hp = hp - 5;
        printf("%u\n", hp);
        printf("%x\n", hp);
        printf("%d\n", 9 / 4 * 4);
        printf("%d\n", (5 >> 1) & 1);
        return 0;
    }
    
    problem.c to run
    #include <stdio.h>
    
    int main(void) {
        int count = 0;
        for (int i = 1; i < 20; i++) {
            if (i % 2 == 0) count++
        }
        printf("%d even numbers from 1 to 20\n", count);
        return 0;
    }
    
    C, 32-bit: int and pointers are 4 bytes

    Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.