CS 101 Databases - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

CS 101 Databases

Description:

CS 221 Chapter 4 Matlab Programming Definite (for) loop startloop=1; endloop=5; sum=0; for i=startloop:endloop; sum=sum+i; end; sum = ? 1 5 10 15 CORRECT None of the ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 31
Provided by: Debb3184
Category:

less

Transcript and Presenter's Notes

Title: CS 101 Databases


1
CS 221 Chapter 4
Matlab Programming
2
Definite (for) loop
startloop1 endloop5 sum0for
istartloopendloop sumsumiend sum ?
3
Definite (for) loop
i1 sum1 i2 sum3 i3 sum6 i4 sum10 i5
sum15 After loop sum 15
4
For loops to access array
for index13 A(index) indexend A(4) ?
5
For loops to access array
A 1 2 3 A(4) does not exist
6
For loops to access array
for r13 for c13 A(r,c) rc
end end A(3,3) ?
7
For loops to access array
A 2 3 4 3 4 5 4
5 6 A(3,3) 6
8
Decision (if) statement
A1 95 A2 95 A3 80 A4 0 if A3 lt A2
fprintf(true) else fprintf(false) end
9
Displayed in command window true
10
Decision (if) statement
A1 95 A2 95 A3 80 A4 0 if A3 A2
fprintf(1\n) elseif A1 lt A2
fprintf(2\n) else fprintf(3\n) end
11
Decision (if) statement
Displayed in command window 3
12
Decision (if) statement
A1 95 A2 95 A3 80 A4 0 if A3 A2
A4 gt 0 fprintf(true) else
fprintf(false) end
13
Displayed in command window
false
14
Decision (if) statement
A1 95 A2 95 A3 80 A4 0 if A1 A2
A4 lt 0 fprintf(true\n) else
fprintf(false\n) end
15
Displayed in command window
true
16
while loop
sum 0 n 1 while n lt 5 sum sum n
n n 1 end sum ?
17
while loop
sum1 n1 sum3 n2 sum6 n3 sum10 n4 sum15
n5 After loop Sum 15
18
while (indefinite) loop
r 1 while r lt 3 c 1 while c lt
3 A(r,c) r c c c 1
end r r 1 end A(3,3) ?
19
while (indefinite) loop
A 2 3 4 3 4 5 4
5 6 A(3,3) 6
20
while (indefinite) loop
r 1 while r lt 3 c 1 while c lt
2 A(r,c) r c c c 1
end r r 1 end A(3,2) ?
21
while (indefinite) loop
A 1 2 2 4 3
6 A(3,2) 6
22
for/if combination
for r 13 for c 13 if r c
A(r,c) r c else
A(r,c) r c end
end end A(3,3) ?
23
for/if combination
A 0 3 4 3 0 5 4
5 0 A(3,3) 0
24
for/while/if combination
for r 13 c 1 while c lt 4
if r c A(r,c) r c
else A(r,c) r - c end
c c 1 end end A(3,1) ?
25
for/while/if combination
A 2 -1 -2 1 4 -1 2
1 6 A(3,1) 2
26
A 1 2 3 4 i 1 while i lt 5      B(i)
A(i)      i i 2 end
  • Program runs correctly
  • 2. Program has an error, will not run CORRECT

27
x 1 while x lt 3      y y x      x x
1 end
  • Program runs correctly
  • 2. Program has an error, will not run CORRECT

28
C(1) 0 for k 2 5      C(k) C(k-1) k
end
  • Program runs correctly CORRECT
  • 2. Program has an error, will not run

29
k 2 i 1 while i lt 5      F(i) k i
     if i gt 2           F(i) k - i     
end    k k 1end
  • Program runs correctly
  • 2. Program has an error, will not run CORRECT

30
On completion of Chapter 4 know
  • Decision (if) statements including elseif, else
  • Definite(for) loops, including nesting
  • Indefinite (while) loops including nesting
  • Relational operators (, lt, gt, lt, gt, )
  • Logical operators ( , , , , )
  • Using the above in combinations
  • Formatted output (fprintf) but no written exam
    questions
Write a Comment
User Comments (0)
About PowerShow.com