• Tidak ada hasil yang ditemukan

Fundamentals of Programming

N/A
N/A
Protected

Academic year: 2025

Membagikan "Fundamentals of Programming"

Copied!
51
0
0

Teks penuh

(1)

Fundamentals of Programming

session 11

More on C

(2)

Remember from last session (Average score)

(3)

Divide by zero!

(4)

Divide by zero!

(5)

Divide by zero!

(6)

Divide by zero!

(7)

printf floating point format

(8)

printf floating point format

(9)

printf floating point format

(10)

printf floating point format

(11)

printf floating point format

https://www.cprogramming.com/tutorial/printf-format-strings.html https://en.wikipedia.org/wiki/Printf_format_string

(12)

Remember from last session (Average score)

(13)

do-while loop

(14)

https://www.cs.uic.edu/~jbell/CourseNotes/C_Programming/Looping.html

(15)

Integer division

(16)

Integer division

(17)

Integer division

(18)

Integer division

(19)

Example: power

Write a program reading a float number "a" and a positive integer "b" and printing ab

(20)

Example: power

(21)

Example: factorial

Write a program readig an integer "n" and printing its factorial (n!).

(22)

operators - precedence

a + b * c

(23)

operators - precedence

a + b * c

a + (b * c)

(24)

operators - precedence

a / b - d * a

(25)

operators - precedence

a / b - d * a

(a / b) - (d * a)

(26)

operators - precedence

a * -b - -c * d

(27)

operators - precedence

a * -b - -c * d

a * (-b) - (-c) * d

(28)

operators - precedence

a * -b - -c * d

(a * (-b)) - ((-c) * d)

(29)

operators - precedence

a / b / c

(30)

operators - precedence

(a / b) / c

(31)

operators - precedence

a - b + c

a + b - c

a * b / c

a / b * c

(32)

operators - precedence

a - b + c (a - b) + c

a + b - c (a + b) - c

a * b / c (a * b) / c

a / b * c (a / b) * c

(33)

Assignment operators

op usage equivalent += a += b a = a + b -= a -= b a = a - b

*= a *= b a = a * b /= a /= b a = a / b

%= a %= b a = a % b

(34)

increment and decrement

op usage equivalent

++ a++ a = a + 1 (*) ++ ++a a = a + 1

-- a-- a = a - 1 (*) -- --a a = a - 1

(35)

Assignment as an operator

(36)

Assignment as an operator

(37)

operators - assignment

a = b = c

(38)

operators - assignment

a = (b = c)

(39)

operators associativity

a = b = c a = (b = c)

a - b - c (a - b) - c

(40)

operators associativity

a = b = c a = (b = c) a - b - c (a - b) - c

right to left

left to right

(41)

operators - assignment

a = b = c = d = e;

(42)

operators - assignment

- - - a

(43)

operators - assignment

- (- (-a))

(44)

operators - assignment

- (- (-a))

right to left

(45)

increment and decrement

(46)

https://www.tutorialspoint.com/cprogramming/c_operators_precedence.htm

(47)

operators - comparison

a + b >= c * d

(48)

operators - comparison

a > b + c && k == d

(49)

operators - comparison

10 > 16 > 20

(50)

operators - comparison

(10 > 16) > 20

(51)

operators - comparison

1 > 20

Referensi

Dokumen terkait

Write a simple announcement for a school activity, for example, a news. reading contest or an English

The Fundamentals of Java Programming Language course provides a conceptual understanding of Object Oriented programming.. The course also teaches students how to use the JAVA 

For example, the following line of code declares a variable to hold an integer value, which is defined by the literal 555:.. var aNumber

The following example demonstrates running Python interactively from the command line and then running the hello.py program.. Executing a

Using these formulas, write a complete C program with a function named flow that returns both the laminar flow velocity, Vlaminar, and the turbulent flow velocity, Vturbulent, using

To support the individual reading activities, the students, for example, can share the books they have read, write a different ending, write a letter to the character in the story, and

11 7.aExplain in detail about the various run time casting in C++ 6 b Write a C++ program for calculating the are of rectangle and circle using run time polymorphism 5 8.a Write a

Fundamentals of Programming lecture 19 Pointers and Arrays, Pointer Arithmetic... Array arguments are