Machine Problems: Arrays
Be the Machine
1. x[1] = 17
2. x[2] = 23
3. n = x[1] + x[2]
4. print n
5. i = 1
6. Print x[i]
7. i = 2
8. Print x[i]
9. Stop.
1. x[1] = 5
2. x[2] = 12
3. x[3] = 4
4. x[4] = 19
5. i = 1
6. print x[i]
7. i = i + 1
8. Stop if i > 4
9. Go to #6.
1. x[1] = 5
2. x[2] = 12
3. x[3] = 4
4. x[4] = 19
5. i = 1
6. w = x[i] + 1
7. print w
8. i = i + 1
9. Go to #6 if i < 5
10. Stop
1. x[1] = 5
2. x[2] = 12
3. x[3] = 4
4. x[4] = 19
5. i = 1
6. p = x[i] + x[i+1]
7. print p
8. i = i + 1
8. If i < 4, Go to #6
9. Stop
1. x[1] = 5
2. x[2] = 12
3. x[3] = 4
4. x[4] = 19
5. b = 0
6. i = 1
7. if x[i] > b, b = x[i]
8. i = i + 1
9. If i < 5, go to #7
10. print "The biggest number is "
11. print b
12. Stop
1. x[1] = 4
2. x[2] = 29
3. x[3] = 6
4. x[4] = 28
5. b = 0
6. i = 1
7. if x[i] > b, b = x[i]
8. i = i + 1
9. If i < 5, go to #7
10. print "The biggest number is "
11. Print b
12. Stop
Using Variables for the Array
1. n[1] = 6
2. n[2] = 3
3. n[3] = 5
4. n[4] = 12
5. i = 1
6. print n[i]
7. i = i + 1
8. if i < 5, go to #6
9. Stop
1. n[1] = 2
2. n[2] =1
3. n[3] = 7
4. n[4] = 13
5. i = 1
6. t = 0
7. t = t + n[i]
8. i = i + 1
9. if i < 5, go to #6
10. print t
11. Stop
Be the Machinemaster
|
|
|
|