1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace OperatorInCSharp
7{
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 // https://learnxinyminutes.com/docs/csharp/
13 ///////////////////////////////////////
14 // Operators
15 ///////////////////////////////////////
16 Console.WriteLine("\n->Operators");
17
18 int i1 = 1, i2 = 2; // Shorthand for multiple declarations
19
20 // Arithmetic is straightforward
21 Console.WriteLine(i1 + i2 - i1 * 3 / 7); // => 3
22
23 // Modulo
24 Console.WriteLine("11%3 = " + (11 % 3)); // => 2
25
26 // Comparison operators
27 Console.WriteLine("3 == 2? " + (3 == 2)); // => false
28 Console.WriteLine("3 != 2? " + (3 != 2)); // => true
29 Console.WriteLine("3 > 2? " + (3 > 2)); // => true
30 Console.WriteLine("3 < 2? " + (3 < 2)); // => false
31 Console.WriteLine("2 <= 2? " + (2 <= 2)); // => true
32 Console.WriteLine("2 >= 2? " + (2 >= 2)); // => true
33
34 // Bitwise operators!
35 /*
36 ~ Unary bitwise complement
37 << Signed left shift
38 >> Signed right shift
39 & Bitwise AND
40 ^ Bitwise exclusive OR
41 | Bitwise inclusive OR
42 */
43
44 // Incrementations
45 int i = 0;
46 Console.WriteLine("\n->Inc/Dec-rementation");
47 Console.WriteLine(i++); //Prints "0", i = 1. Post-Incrementation
48 Console.WriteLine(++i); //Prints "2", i = 2. Pre-Incrementation
49 Console.WriteLine(i--); //Prints "2", i = 1. Post-Decrementation
50 Console.WriteLine(--i); //Prints "0", i = 0. Pre-Decrementation
51
52 //
53 // TODO: Viết chương trình tính Hằng đẳng thức
54 // https://vi.wikipedia.org/wiki/B%E1%BA%A3y_h%E1%BA%B1ng_%C4%91%E1%BA%B3ng_th%E1%BB%A9c_%C4%91%C3%A1ng_nh%E1%BB%9B
55 // Write a program to calculate (a+b)2.
56 // Hint: (a * a + b * b + 2 * a * b)
57 //
58
59
60
61
62 //
63 // TODO: Viết chương trình tính Diện tích hình tròn
64 // https://www.mathsisfun.com/geometry/circle-area.html
65 // Write a program to calculate formulae A = (π * r * 2).
66 //
67
68
69
70 //
71 // TODO: Viết chương trình tính Diện tích Tam giác
72 // https://www.mathsisfun.com/algebra/trig-area-triangle-without-right-angle.html
73 //
74 }
75 }
76}