C Programming Lecture Notes: Conditional and Loop Statements, Lecture notes of Data Structures and Algorithms

A set of lecture notes for a c programming course, covering conditional statements (if, else if, else) and loop statements (while, for, for-for). It includes examples and exercises.

Typology: Lecture notes

2018/2019

Uploaded on 09/24/2019

unknown user
unknown user 🇰🇷

6 documents

1 / 24

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 02
C program 조건문, 반복문 I
if … else if … else
while
for
for … for …
random number
array
break / continue
sorting
2-dim array
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download C Programming Lecture Notes: Conditional and Loop Statements and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Lecture 02

C program 조건문, 반복문 I

  • if … else if … else …
  • while
  • for
  • for … for …
  • random number
  • array
  • break / continue
  • sorting
  • 2-dim array

Find the root of the first-order equation

a x + b = 0, what is the solution of x?

if (a == 0 && b != 0) x =? if (a == 0 && b == 0) x =?

if … else if … else … 2

if-statement example

4

if-statement example

5

 반복 문 for 구조

for 다음에 괄호() 구성

 초기화(Initialization), 조건검사(conditional expression), 증감연산(increment)의 세 부분으로 구성되고  이를 세미콜론(;) 으로 구분

for 문

7

 반복문 for 구조

c

for 문

for ( i = 0 ; i < 5 ; i++ ){

printf(“*****\n”);

증감 연산자

i < 5 거짓

I의 값 : i = 0 i = 0 i = 0 i = 1 i = 1 i = 1 i = 2

i = 5

8

for 문 예제 (Exercise)

 구구단 2 단을 거꾸로 출력

10

Question 1

A snail is now at the bottom of a 3 m-deep well. This snail can climb up 55 cm along the wall during the day, but slide 13 cm down during the night.How many days will it take the snail to get out of the well?

11

forwith array

for 문 , array

13

 변수 또는 배열의 크기를 구하는‘연산자’

14

sizeof

16

for … for …

17

array

19

Random number

Sorting numbers in an array

20

sorting

main(){ int A[10];

for (i=0; i < 10; i++) A[j] = rand() % 100;

for (i=0; i < 10; i++) for(j=i+1; j < 10; j++) if (A[i] < A[j]) { temp = A[i]; A[i]= A[j]; A[j] = temp; } }