Advertisement
Guest User

Tìm ra 3 số lớn nhất trong một vòng lặp

a guest
Feb 17th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. int first = 1, second = 1, three = 1, n;
  7.  
  8. cout << "Nhap so phan tu cua mang: " << endl;
  9. cin >> n;
  10. if (n >= 1 && n <= 1000)
  11. {
  12. int arr[n];
  13. for(int i = 0; i < n; i++)
  14. {
  15. cout << "nhap phan tu thu " << i << ": ";
  16. cin >> arr[i];
  17.  
  18. if(arr[i] > first){
  19. first = arr[i];
  20. }
  21. else if (arr[i] > second)
  22. {
  23. three = second;
  24. second = arr[i];
  25. }
  26. else if (arr[i] > three)
  27. {
  28. three = arr[i];
  29. }
  30. }
  31. cout << first << " " << second << " " << three;
  32.  
  33. }
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement