fork download
  1. #include <stdio.h> // Thư viện để dùng hàm scanf và printf
  2.  
  3. int main() {
  4. float side; // Khai báo biến thực để chứa cạnh hình vuông
  5. float area, perimeter; // Khai báo biến diện tích và chu vi
  6.  
  7. printf("Enter the length of one side of the square: "); // Nhắc người dùng nhập độ dài
  8. scanf("%f", &side); // Đọc giá trị thực từ bàn phím và lưu vào biến side
  9.  
  10. area = side * side; // Diện tích = cạnh × cạnh
  11. perimeter = 4 * side; // Chu vi = 4 × cạnh
  12.  
  13. printf("Area = %.2f\n", area); // In ra diện tích với 2 chữ số thập phân
  14. printf("Perimeter = %.2f\n", perimeter); // In ra chu vi với 2 chữ số thập phân
  15.  
  16. return 0; // Kết thúc chương trình
  17. }
  18.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Enter the length of one side of the square: Area = 0.00
Perimeter = 0.00