Условията и решенията на задачите за домашно от раздела оператори и изрази.
Odd or Even
Task: Write an expression that checks if given integer is odd or even.
Can be Divided
Task: Write a boolean expression that checks for given integer if it can be divided (without remainder) by 7 and 5 in the same time.
Rectangle Area
Task: Write an expression that calculates rectangle’s area by given width and height.
Is Digit Seven
Task: Write an expression that checks for given integer if its third digit (right-to-left) is 7. E. g. 1732 –> True.
One or Zero
Task: Write a boolean expression for finding if the bit 3 (counting from 0) of a given integer is 1 or 0.
Circle Point
Task: Write an expression that checks if given point (x, y) is within a circle K(O, 5).
Is Prime
Task: Write an expression that checks if given positive integer number n (n ≤ 100) is prime. E.g. 37 is prime.
Trapezoid Area
Task: Write an expression that calculates trapezoid’s area by given sides a and b and height h.
Circle and Rectangle Point
Task: Write an expression that checks for given point (x, y) if it is within the circle K( (1,1), 3) and out of the rectangle R(top=1, left=-1, width=6, height=2).
Is Value of One
Task: Write a boolean expression that returns if the bit at position p (counting from 0) in a given integer number v has value of 1. Example: v=5; p=1 –> false.
Extracts Bit Number
Task: Write an expression that extracts from a given integer i the value of a given bit number b. Example: i=5; b=2 –> value=1.
Sequence of Operators
Task: We are given integer number n, value v (v=0 or 1) and a position p. Write a sequence of operators that modifies n to hold the value v at the position p from the binary representation of n. Example: n = 5 (00000101), p=3, v=1 –> 13 (00001101) n = 5 (00000101), p=2, v=0 –> 1 (00000001)
Bits Exchange
Task: Write a program that exchanges bits 3, 4 and 5 with bits 24, 25 and 26 of given 32-bit unsigned integer.