chapter two operators and expressions lesson seven
TRANSCRIPT
![Page 1: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/1.jpg)
Chapter Two
Operators and ExpressionsLesson Seven
![Page 2: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/2.jpg)
What is Operator
Operators allow processing of primitive data types and objects. They take as an input one or more operands and return some value as a result.
![Page 3: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/3.jpg)
Operators in C# can be separated in several different categories:
- Arithmetic operators – they are used to perform simple mathematical operations.
- Assignment operators – allow assigning values to variables.
- Comparison operators – allow comparison of two literals and/or variables.
- Logical operators – operators that work with Boolean data types and Boolean expressions.
![Page 4: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/4.jpg)
Category and OperatorsCategory Operatorsarithmetic -, +, *, /, %, ++, --logical &&, ||, !, ^comparison ==,!=, >, <, >=, <=assignment =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=string concatenation +
![Page 5: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/5.jpg)
Arithmetical Operators
The arithmetical operators in C# +, -, * are the same like the ones in math. They perform addition, subtraction and multiplication on numerical values and the result is also a numerical value.
![Page 6: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/6.jpg)
Division is Different
The division operator / has different effect on integer and real numbers. When we divide an integer by an integer (like int,) the returned value is an integer (no rounding, the fractional part is cut).
Such division is called an integer division. Example of integer division: 7 / 3 = 2.
![Page 7: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/7.jpg)
Remainder of Devision
The remainder of integer division of integers can be obtained by the operator %. For example, 7 % 3 = 1, and –10 % 2 = 0.
![Page 8: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/8.jpg)
Dividing A real Number
When dividing two real numbers or two numbers, one of which is real (e.g. float, double, etc.), a real division is done (not integer), and the result is a real number with a whole and a fractional part. For example: 5.0 / 2 = 2.5.
![Page 9: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/9.jpg)
incrementdecrement(++ and --)
The operator for increasing by one (increment) ++ adds one unit to the value of the variable, respectively the operator -- (decrement) subtracts one unit from the value.
![Page 10: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/10.jpg)
Example { int squarePerimeter = 19; double squareSide = squarePerimeter / 6.0; double squareArea = squareSide * squareSide; Console.WriteLine(squareSide); Console.WriteLine(squareArea); int a = 5; int b = 10; Console.WriteLine(a + b); Console.WriteLine(a + (++b)); Console.WriteLine(a + b); Console.WriteLine(14 / a); Console.WriteLine(14 % a); Console.ReadKey(); }
![Page 11: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/11.jpg)
Exercise 1) Qor program ka shaqeynayo areada
trapezium adigoo weydinayo in uu userka soo galiyo qiima a, b iyo h
Note: hadii maada xisaabta mar hore kugu dambeesay trapezium areadiisa waxaa lagu helaa
xusuusnow xisaabtu muhiim ayee u tahay programming
![Page 12: Chapter Two Operators and Expressions Lesson Seven](https://reader036.vdocuments.us/reader036/viewer/2022083009/5697c01c1a28abf838ccff5e/html5/thumbnails/12.jpg)
NEXT LESSON
Logical Operators