# Python, C++ and Pascal - side by side comparison ## Cấu trúc chương trình ### Python ```python= print("Hello World!") ``` ### C++ ```cpp= #include <iostream> using namespace std; int main() { cout << "Hello World!" << endl; } ``` ### Pascal ```pascal= begin writeln ('Hello World!') end. ``` ## Khai báo và khởi tạo biến Khai báo và khởi tạo 3 biến với 3 kiểu dữ liệu: *số nguyên*, *số thực* và *xâu ký tự*. ### Python ```python= n = 5 x = 2.0 s = "uCode.vn" print(n, x, s, sep='\n') ``` ### C++ ```cpp= #include <iostream> using namespace std; int main() { int n = 5; double x = 2.5; string s = "uCode.vn"; cout << n << endl << x << endl << s << endl; } ``` ### Pascal ```pascal= var n: integer = 5; x: double = 2.5; s: string = 'uCode.vn'; begin writeln(n); writeln(x); writeln(s); end. ``` ## In ra số thực có định dạng In ra số thực với 3 chữ số sau dấu phẩy: ### Python ```python= x = 2.53625 y = 3.1 print("%.3f" % x) print("%.3f" % y) ``` ### C++ ```cpp= #include <iostream> #include <iomanip> using namespace std; int main() { double x = 2.53625; double y = 3.1; cout << fixed << setprecision(3) << x << endl; cout << y; } ``` ### Pascal ```pascal= program Hello; var x: double = 2.53625; y: double = 3.1; begin writeln(x:0:3); writeln(y:0:3); end. ``` ### Kết quả ```shell= 2.536 3.100 ``` ## Các phép toán số học ### Python ```python= print(3 + 4) ``` ### C++ ```cpp= ``` ### Pascal ```pascal= ``` ## ### Python ```python= ``` ### C++ ```cpp= ``` ### Pascal ```pascal= ``` ## ### Python ```python= ``` ### C++ ```cpp= ``` ### Pascal ```pascal= ```