Checkpoint: the foundations
Learn
Before the memory lessons
Four problems that use everything so far: printf, scanf, types, division, if and loops, functions and bits. No starter scaffolding beyond what a real task gives you, and no hints until your first check. Next up is where values actually live in memory, so this is a good moment to find out what has stuck.
Checkpoint
Season stats from input
The input is a count n, then n scores. Print one line: how many scores, their total, the average to one decimal place and the best score. Check runs three different inputs, including one where every score is negative.
For 4 then 10 20 35 41 the line is count 4, total 106, average 26.5, best 41.
Milestones
- Four scores
- All negative
- Just one
On your own: hints appear after your first check, a solution after 3 checks or if you give up.
Your program reads the Input box under the editor. Check also tries 2 other inputs.
#include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
return 0;
}
CheckpointPredict the output
Damage on an unsigned byte
A character's health is stored in an unsigned char. Type exactly what this prints.
Read the program, type exactly what it prints, then lock it in. It runs after that.
#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;
}
CheckpointFix the bug
Nine evens out of twenty
This should count the even numbers from 1 to 20 inclusive and print 10 even numbers from 1 to 20. It has two problems. Fix both.
On your own: hints appear after your first check, a solution after 3 checks or if you give up.
#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;
}
Checkpoint
Battle pass tiers
A battle pass starts at tier 1 with 0 XP. Each tier costs 100 XP more than the one before: tier 2 needs 100 XP in total, tier 3 needs 300 (100 + 200), tier 4 needs 600 (300 + 300), and so on with no top tier. Write two functions, for any xp of 0 or more:
int tier_for(int xp)returns the tier reached with that much XP.int xp_to_next(int xp)returns how much more XP the next tier needs.
On your own: hints appear after your first check, a solution after 3 checks or if you give up.
Cleared
Go back to
You can now
Save your progress to a free account
Next up: Core, with Premium
Where values live: stack frames, arrays, strings as bytes, pointers and structs, plus the string library and reading input safely.
- 08Functions and the stack
- 09Arrays in memory
- 10Strings are char arrays
- 11Pointers and addresses
- 12Pass by value, pass a pointer
- 13Pointer arithmetic
- 14Checkpoint: functions, arrays and pointers
- 15The string library
- 16Reading lines of input
- 17Structs and padding
- 18Checkpoint: text and structs
Premium is £7.99 a month or £59 a year and opens every lesson after Foundations, in all four courses. What is included