fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cout << "Nhap so luong phan tu: ";
  7. cin >> n;
  8.  
  9. int x, max;
  10.  
  11. cout << "Nhap so thu 1: ";
  12. cin >> max; // giả sử số đầu tiên là lớn nhất
  13.  
  14. for(int i = 2; i <= n; i++) {
  15. cout << "Nhap so thu " << i << ": ";
  16. cin >> x;
  17.  
  18. if(x > max) {
  19. max = x;
  20. }
  21. }
  22.  
  23. cout << "So lon nhat la: " << max;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5320KB
stdin
3 
1 2 3
stdout
Nhap so luong phan tu: Nhap so thu 1: Nhap so thu 2: Nhap so thu 3: So lon nhat la: 3