42
problem set 0 https://www.cs50.net/psets/0/

problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

problem set 0https://www.cs50.net/psets/0/

Page 2: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

office hours

Page 3: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

walkthrough

Page 4: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

scribe notes

Page 5: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

sectioning

Page 6: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000
Page 7: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

intmain(){        printf("O  hai,  world!\n");}

Page 8: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

statements

Page 9: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

statements

printf("O  hai,  world!\n");

Page 10: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

loops

Page 11: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

loops

while  (true){        printf("O  hai!\n");}

Page 12: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

loops

Page 13: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

loops

for  (int  i  =  0;  i  <  10;  i++){        printf("O  hai!\n");}

Page 14: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

variables

Page 15: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

variables

int  counter  =  0;while  (true){        printf("%d\n",  counter);        counter++;}

Page 16: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

Boolean expressions

Page 17: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

Boolean expressions

(x  <  y)((x  <  y)  &&  (y  <  z))

Page 18: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

conditions

Page 19: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

conditions

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");}

Page 20: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

arrays

string  inventory[1];inventory[0]  =  "Orange";

Page 21: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

#include  <stdio.h>

intmain(void){        printf("O  hai,  world!\n");}

Page 22: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

10000011 00000001 00010001 00000000 00111101 11111100 01110100 0011110100000000 01000000 00000000 00000000 00000000 00000000 00000000 0000000010010000 00000000 00000000 00000000 01010000 00000000 00000111 0011000000001011 00000001 00001011 00000011 00001010 00000000 00000000 0000000000000000 00100000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00100000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 00000000 0000000001110000 00010000 00000000 00100000 00000001 00000000 00000000 0000000000000000 00000000 00000000 00100000 00000001 00000000 00000000 0000000000000000 00000000 00000000 01000000 00000001 00000000 00000000 0000000000000000 00100000 00000000 01000000 00000001 00000000 00000000 0000000011111111 11111111 11111111 11111111 11111111 11111111 11111111 1111111110010000 10000000 00000000 01000000 00000001 00000000 00000000 0000000000101110 01100100 01111001 01101110 01100001 01101101 01101001 0110001110110000 00000100 00000000 00100000 00000001 00000000 00000000 0000000010110000 00000100 00000000 00100000 00000001 00000000 00000000 0000000010100000 00000001 00000000 00000000 00000000 00000000 00000000 0000000010110000 00000100 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00100000 00000000 00000000

...

Page 23: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

CS50 Appliance

Page 24: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000
Page 25: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

how to write a program

Page 26: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

how to compile a programgcc  hello.c

Page 27: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

how to run a program./a.out

Page 28: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

how to compile a programgcc  -­‐o  hello  hello.c

Page 29: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

how to run a program./hello

Page 30: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

how to compile a programmake  hello

Page 31: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

functionsmain

Page 32: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

Standard Librarystdio.h

printf

...

Page 33: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

CS50 Librarycs50.h

GetChar

GetDouble

GetFloat

GetInt

GetLongLong

GetString

Page 34: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

printf%c      %d      %f      %lld      %s      ...

Page 35: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

escape sequences\n      \r      \t      \'      \"      \\      \0      ...

Page 36: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

math+      -­‐      *      /      %

Page 37: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

primitive typeschar      double      float      int      long  long      ...

Page 38: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

CS50 typesbool      string      ...

Page 39: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

http://www.difranco.net/cop2220/op-prec.htm

precedence

Page 40: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

how to compile a programgcc  -­‐o  hello  hello.c  -­‐lcs50

Page 41: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

how to compile a programmake  hello

Page 42: problem set 0 - CS50cdn.cs50.net/2011/fall/lectures/1/week1w.pdf · 2012-08-22 · 10000011 00000001 00010001 00000000 00111101 11111100 01110100 00111101 00000000 01000000 00000000

to be continued...