Lecture 01 - Introduction
Lecture 01 - Introduction
“Everybody … should learn to program a computer ... because it teaches you to think.”
- Steve Jobs
Computational Thinking
• Knowledge
CSE102
Computer Programming with C
2021-2022 Spring Semester
Introduction to CSE102
© 2015-2022 Yakup Genç
February 2022 CSE341 Lecture 1.1 3 February 2022 CSE341 Lecture 1.1 4
1
3/9/2022
February 2022 CSE341 Lecture 1.1 5 February 2022 CSE341 Lecture 1.1 6
February 2022 CSE341 Lecture 1.1 7 February 2022 CSE341 Lecture 1.1 8
2
3/9/2022
February 2022 CSE341 Lecture 1.1 9 February 2022 CSE341 Lecture 1.1 10
February 2022 CSE341 Lecture 1.1 11 February 2022 CSE341 Lecture 1.1 12
3
3/9/2022
February 2022 CSE341 Lecture 1.1 13 February 2022 CSE341 Lecture 1.1 14
February 2022 CSE341 Lecture 1.1 15 February 2022 CSE341 Lecture 1.1 16
4
3/9/2022
February 2022 CSE341 Lecture 1.1 17 February 2022 CSE341 Lecture 1.1 18
February 2022 CSE341 Lecture 1.1 19 February 2022 CSE341 Lecture 1.1 20
5
3/9/2022
February 2022 CSE341 Lecture 1.1 21 February 2022 CSE341 Lecture 1.1 22
February 2022 CSE341 Lecture 1.1 23 February 2022 CSE341 Lecture 1.1 24
6
3/9/2022
February 2022 CSE341 Lecture 1.1 25 February 2022 CSE341 Lecture 1.1 26
February 2022 CSE341 Lecture 1.1 27 February 2022 CSE341 Lecture 1.1 28
7
3/9/2022
February 2022 CSE341 Lecture 1.1 29 February 2022 CSE341 Lecture 1.1 30
February 2022 CSE341 Lecture 1.1 31 February 2022 CSE341 Lecture 1.1 32
8
3/9/2022
Variables Variables
• Variables: memory cells for storing data • Data types: abstraction of real types
− Values can change − Predefined data types
• Every variable has: − User-defined data types
− Name: identifier
− Each constant or variable has a type
− Type: int, double, char
− Size − int: whole numbers (-123, 15, 27384)
− Value • There is a range because of finite memory cell size
February 2022 CSE341 Lecture 1.1 33 February 2022 CSE341 Lecture 1.1 34
February 2022 CSE341 Lecture 1.1 35 February 2022 CSE341 Lecture 1.1 36
9
3/9/2022
February 2022 CSE341 Lecture 1.1 37 February 2022 CSE341 Lecture 1.1 38
10
3/9/2022
printf(format string, print list); \n Newline. Position the cursor at the beginning of the next line.
\t Horizontal tab. Move the cursor to the next tab stop.
• Function name: printf
• Function arguments: in paranthesis \a Alert. Sound the system bell.
• Format string: “That equals %f kilometers.\n” \\ Backslash. Insert a backslash character in a string.
• Print list: kms
\" Double quote. Insert a double-quote character in a string.
• Placeholders: %c, %d, %f, %lf
• Escape sequence:
• \n means newline : cursor moves the beginning of the next line
• Can be used anywhere in the format string
February 2022 CSE341 Lecture 1.1 41 February 2022 CSE341 Lecture 1.1 42
February 2022 CSE341 Lecture 1.1 43 February 2022 CSE341 Lecture 1.1 44
11
3/9/2022
February 2022 CSE341 Lecture 1.1 45 February 2022 CSE341 Lecture 1.1 46
12
3/9/2022
February 2022 CSE341 Lecture 1.1 49 February 2022 CSE341 Lecture 1.1 50
February 2022 CSE341 Lecture 1.1 51 February 2022 CSE341 Lecture 1.1 52
13
3/9/2022
• Evaluation Rules:
• Parenthesis rule:
• All expressions in parenthesis are evaluated separately
• Nested parenthesis evaluated inside out
• Precedence rule:
• There is an evaluation order in operators
• Unary +, -
• *, / , %
• Binary +, -
• Associativity rule:
• Operators in the same sub-expression and at the same precedence level
• Unary: right to left
• Binary: left to right
February 2022 CSE341 Lecture 1.1 53 February 2022 CSE341 Lecture 1.1 54
February 2022 CSE341 Lecture 1.1 55 February 2022 CSE341 Lecture 1.1 56
14
3/9/2022
February 2022 CSE341 Lecture 1.1 57 February 2022 CSE341 Lecture 1.1 58
February 2022 CSE341 Lecture 1.1 59 February 2022 CSE341 Lecture 1.1 60
15
3/9/2022
February 2022 CSE341 Lecture 1.1 61 February 2022 CSE341 Lecture 1.1 62
February 2022 CSE341 Lecture 1.1 63 February 2022 CSE341 Lecture 1.1 64
16
3/9/2022
• Interactive mode
• Batch mode
• Input Redirection: standard input is associated with a file instead of keyboard
myprog < inputfile
• No need to display prompting message
• Display the message about input (echo print)
• Output Redirection: standard output is associated with a file instead of screen
myprog > outputfile
• Can print the file to get the hardcopy
February 2022 CSE341 Lecture 1.1 65 February 2022 CSE341 Lecture 1.1 66
17
3/9/2022
February 2022 CSE341 Lecture 1.1 69 February 2022 CSE341 Lecture 1.1 70
February 2022 CSE341 Lecture 1.1 71 February 2022 CSE341 Lecture 1.1 72
18
3/9/2022
February 2022 CSE341 Lecture 1.1 73 February 2022 CSE341 Lecture 1.1 74
19