<style>
img {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
[TOC]
## Week 0 - Scratch
- 進制/ASCII/Unicode
- Pseudocode/複雜度
- Algorithm/Artificial Intelligence
- Scratch
## Week 1 - C
- Compiler
- Source Code $\rightarrow$ Machine Code
- [Visual Code for CS50](https://cs50.dev/)
```c
// hello.c
#include <stdio.h>
int main(void){
printf("hello, world\n");
}
```
- [Manual pages for the C standard library](https://manual.cs50.io/)
```c
// hello.c
#include <stdio.h>
#include <cs50.h>
int main(void) {
string answer = get_string("What's your name? ");
printf("hello, %s\n", answer);
}
```
```c
// comapre.c
#include <stdio.h>
#include <cs50.h>
int main(void) {
int x = get_int("What's x? ");
int y = get_int("What's y? ");
if (x < y) {
printf("x is less than y\n");
} else if (x > y) {
printf("x is greater than y\n");
} else {
printf("x is equal to y\n");
}
}
```
```c
// agree.c
#include <stdio.h>
int main() {
char c = get_char("Do you agree? ");
if (c == 'y' || c == 'Y') {
printf("Agreed.\n");
} else if (c == 'n' || c == 'N') {
printf("Not agreed.\n");
}
}
```
```c
// meow.c
#include <stdio.h>
int main() {
int i = 0;
while (i < 3) {
printf("meow\n");
i++;
}
}
```
```c
// meow.c
#include <stdio.h>
void meow(void) {
printf("Meow!\n");
}
// First void means that the function does not return a value
// Second void means that the function does not accept any arguments
int main(void) {
meow();
}
```
```c
// meow.c
#include <stdio.h>
void meow(int n);
int main(void) {
meow(3);
}
void meow(int n) {
for (int i = 0; i < n; i++) {
printf("meow\n");
}
}
```
```c
// calculator.c
#include <cs50.h>
#include <stdio.h>
int add(int a, int b);
int main(void) {
int x = get_int("x: ");
int y = get_int("y: ");
printf("%i\n", add(x, y));
}
int add(int a, int b) {
return a + b;
}
```
- Graphic User Interface (GUI)
- Commandline
```c
// calculator.c
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int x = get_int("x: ");
int y = get_int("y: ");
printf("%.20f\n", (double) x / (double) y);
}
```
### Data Types
- integer / unsigned integer / chat / float / double / bool / string
- void
### Operators
- $+$, $-$, $*$, $/$, $\%$
- true / false
- $\&\&$, $||$, $!$
- $>$, $<$, $>=$, $<=$
- $!=$, $==$
### Conditional Statements
- if / else / else if
- switch
- case
- default
- ?:
```c
int x;
if (expr) {
x = 5;
} else {
x = 6;
}
// int x = (expr) ? 5 : 6;
```
### Loops
- while / do-while
- for
```c
for (start; expr; increment) {
}
```
### Command Line
- `ls`: list
- `cd`: change directory
- `pwd`: print work directory
- `cp`: copy
- `rm`: remove
- `rm -f <file>`
- `rm -r <directory>`
- `mv`: move

## Week 2 - Arrays
- make / [clang](https://zh.wikipedia.org/zh-tw/Clang)
1. preprocessing
2. compiling
3. assembling
4. linking
- Debugger / [Rubber duck debugging](https://zh.wikipedia.org/wiki/%E5%B0%8F%E9%BB%84%E9%B8%AD%E8%B0%83%E8%AF%95%E6%B3%95)

```c
// scores.c
#include <stdio.h>
#include <cs50.h>
int main(void) {
int scores[3];
for (int i = 0; i < 3; i++) {
scores[i] = get_int("Score: ");
}
printf("Average: %f\n", (scores[0] + scores[1] + scores[2]) / 3.0);
}
```
```c
// hi.c
#include <stdio.h>
#include <cs50.h>
int main(void) {
string s = "hi!";
printf("%c%c%c\n", s[0], s[1], s[2]);
}
```
```c
// hi.c
#include <stdio.h>
#include <cs50.h>
int main(void) {
string words[2];
words[0] = "HI!";
words[1] = "BYE!";
printf("%c%c%c\n", words[0][0], words[0][1], words[0][2]);
printf("%c%c%c%c\n", words[1][0], words[1][1], words[1][2], words[1][3]);
}
```
```c
// hi.c
#include <stdio.h>
#include <cs50.h>
int main(void) {
string words[1];
words[0] = "HI!";
printf("%i %i %i %i\n", words[0][0], words[0][1], words[0][2], words[0][3]);
// 72 73 33 0
}
```
```c
// length.c
#include <stdio.h>
#include <cs50.h>
int string_length(string s);
int main(void) {
string name = get_string("Name: ");
int length = string_length(name);
printf("%i\n", length);
}
int string_length(string s) {
int i = 0;
while (s[i] != '\0') {
i++;
}
return i;
}
```
```c
// string.c
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main(void) {
string s = get_string("Input: ");
printf("Output: ");
for (int i = 0; i < strlen(s); i++) {
printf("%c", s[i]);
}
printf("\n");
}
```
```c
// uppercase.c
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
int main(void) {
string s = get_string("Before: ");
printf("After: ");
for (int i = 0, n = strlen(s); i < n; i++) {
printf("%c", toupper(s[i]));
}
printf("\n");
}
```
```c
// greet.c
#include <stdio.h>
#include <cs50.h>
int main(int argc, string argv[]) {
if (argc == 2)
printf("hello, %s\n", argv[1]);
else
printf("hello, world\n");
}
```
```c
// status.c
#include <cs50.h>
#include <stdio.h>
int main(int argc, string argv[]) {
if (argc != 2) {
printf("Missing command-line argument\n");
return 1;
}
printf("hello, %s\n", argv[1]);
return 0;
}
```
### Functions
### Variables and Scope
### Debugging (“Step through”)
### Duplicate of 'Debugging (“Step into”)'
### Arrays
### Command Line Arguments
## Week 3 - Algorithms
## Week 4 - Memory
## Week 5 - Data Structures
## Week 6 - Python
## Artificial Intelligence
## Week 7 - SQL
## Week 8 - HTML, CSS, JavaScript
## Week 9 - Flask
## Week 10 - Cybersecurity
## Reference
[Problem Set](https://cs50.harvard.edu/x/2024/psets/0/)
[Progress](https://cs50.me/cs50x)