1.5 Conditional Statements academy.zariba.com 1. Lecture Content 1.If-else statements 2.If-else-if...
-
Upload
leon-harrell -
Category
Documents
-
view
230 -
download
1
Transcript of 1.5 Conditional Statements academy.zariba.com 1. Lecture Content 1.If-else statements 2.If-else-if...
1
1.5 Conditional Statements
academy.zariba.com
2
Lecture Content
1. If-else statements2. If-else-if statements3. Switch-case statements
3
Comparison Operators
Operator Notation
Equals ==
Not Equals !=
Greater Than >
Greater Than or Equals >=
Less Than <
Less Than or Equals <=
4
Logical Operators
Operator Notation
Not !
And &&
Or ||
XOr ^
5
1. If-else and if-else-if Statments
6
2. Switch Case statements
7
Homework
1. Write an if statement that exchanges the values of 2 numbers if the first is bigger than the second
2. Write a program that finds the largest of 3 integers, using if statements.
3. Sort 3 integer numbers using if statements.4. Write a program that enters a number from 10 to 19 and prints
on the console the name of the number. E.g. 11 – “eleven”. Use switch.
5. Write a boolean expression for finding if the bit 2 (counting from 0) of a given integer is 1 or 0.
6. Write an expression that checks if a given point (x,y) is within a circle with radius 4 and centre at (0,0)
7. *We are given 5 integer numbers. Write a program that checks if there is a subset of these 5 numbers which sums to zero. List all such sums. E.g. 5,0,-2,-3,1 should print 1.) 0 =0 2.) 5-2-3=0.
8
References
9
Zariba Academy
Questions