Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pseudo-Code Conditional Branches

Similar presentations


Presentation on theme: "Pseudo-Code Conditional Branches"— Presentation transcript:

1 Pseudo-Code Conditional Branches
Class Activity ICS B Spring 2015 Anham Liaqat

2 Exercise 1 Input Variable: X Pseudocode: Z = 1 INPUT X OUTPUT Z
What is output of above program if input is a) X is 3 b) X is 4 c) X is 2 IF X is less than 4 Z = 2 END IF

3 Exercise 2 Input Variable: X Pseudocode: Z = 1 INPUT X OUTPUT Z
What is output of above program if input is a) X is 1 b) X is 5 c) X is 4 IF X is less than 4 Z = 2 ELSE Z = 4 END IF

4 Exercise 3 Input Variable: X Pseudocode: Z = 1 INPUT X OUTPUT Z
What is output of above program if input is a) X is 3 b) X is 4 c) X is 1 IF X is less than 4 Z = 1 END IF IF X is equal to 3 Z = 2 END IF

5 Exercise 4 Input Variable: X Pseudocode: Z = 1 INPUT X OUTPUT Z
What is output of above program if input is a) X is 3 b) X is 4 c) X is 2 IF X is less than 4 Z = 3 END IF IF X is equal to 3 Z = 2 END IF

6 Exercise 5 Z = 1 INPUT X INPUT Y OUTPUT Z Input Variables: X, Y
Pseudocode: Z = 1 INPUT X INPUT Y OUTPUT Z What is output of above program if input is X is 3 and Y is 4 X is 3 and Y is 2 X is 2 and Y is 3 IF X is equal to 3 END IF IF Y is greater than X Z = 4 ELSE Z = 5 END IF

7 Exercise 6 Input Variable: X Pseudocode: INPUT X Z = 1 OUTPUT Z
IF X is less than 4 Z = 1 ELSE END IF  1.What is output of this program if input is X is 3 X is 4 X is 5 2. For what input in X, the output variable Z is set to 2? IF X is equal to 3 Z = 2 ELSE END IF IF X is equal to 4 Z = 3 ELSE Z = 4 END IF

8 Exercise 7 Write pseudocode for a program which takes a year as input (e.g. 2014) and determines whether or not it is a leap year. A leap year is a multiple of 4, and if it is a multiple of 100, it must also be a multiple of 400.

9 Exercise 7 Solution There are more then one solutions. This is only one of them

10 Exercise 8 Write and run a program that plays the game of “Rock, paper, scissors.” In this game, two players simultaneously say (or display a hand symbol representing) either “rock,” “paper,” or “scissors.” The winner is the one whose choice dominates the other.. The rules are: paper dominates (wraps) rock, rock dominates (breaks) scissors, and scissors dominate (cut) paper. You can use 1=rock,2=paper,3=scissors Sample Input: 1 1 Sample Output: Draw Sample Input: 1 2 Sample Output: 2nd player wins

11 Exercise 8 Solution There are more then one solutions. This is only one of them


Download ppt "Pseudo-Code Conditional Branches"

Similar presentations


Ads by Google