Mô tả bài toán
Tạo ứng dụng Console, sử dụng các Toán tử (Operator) để tính toán:- Hằng đẳng thức: (a + b)2
- Diện tích hình tròn: A = π * r * 2
- Diện tích Tam giác: A = ½ * b * h
Cách giải quyết
Xem source code Tham khảo để biết cách sử dụng Toán tử (operator) trong C#.Source code
csharp
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5 6namespace OperatorInCSharp7{8 class Program9 {10 static void Main(string[] args)11 {12 // https://learnxinyminutes.com/docs/csharp/13 ///////////////////////////////////////14 // Operators15 ///////////////////////////////////////16 Console.WriteLine("\n->Operators");17 18 int i1 = 1, i2 = 2; // Shorthand for multiple declarations19 20 // Arithmetic is straightforward21 Console.WriteLine(i1 + i2 - i1 * 3 / 7); // => 322 23 // Modulo24 Console.WriteLine("11%3 = " + (11 % 3)); // => 225 26 // Comparison operators27 Console.WriteLine("3 == 2? " + (3 == 2)); // => false28 Console.WriteLine("3 != 2? " + (3 != 2)); // => true29 Console.WriteLine("3 > 2? " + (3 > 2)); // => true30 Console.WriteLine("3 < 2? " + (3 < 2)); // => false31 Console.WriteLine("2 <= 2? " + (2 <= 2)); // => true32 Console.WriteLine("2 >= 2? " + (2 >= 2)); // => true33 34 // Bitwise operators!35 /*36 ~ Unary bitwise complement37 << Signed left shift38 >> Signed right shift39 & Bitwise AND40 ^ Bitwise exclusive OR41 | Bitwise inclusive OR42 */43 44 // Incrementations45 int i = 0;46 Console.WriteLine("\n->Inc/Dec-rementation");47 Console.WriteLine(i++); //Prints "0", i = 1. Post-Incrementation48 Console.WriteLine(++i); //Prints "2", i = 2. Pre-Incrementation49 Console.WriteLine(i--); //Prints "2", i = 1. Post-Decrementation50 Console.WriteLine(--i); //Prints "0", i = 0. Pre-Decrementation51 52 //53 // TODO: Viết chương trình tính Hằng đẳng thức54 // 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%9B55 // 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òn64 // https://www.mathsisfun.com/geometry/circle-area.html65 // 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ác72 // https://www.mathsisfun.com/algebra/trig-area-triangle-without-right-angle.html73 //74 }75 }76}
