Advertisement
gosuodin

MAX MIN

Jun 6th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main()
  6. {
  7. int n;
  8. cout << "nhap n :";
  9. cin >> n;
  10. int *a = new int[n];
  11. for (int i = 0; i < n; i++) {
  12. cout << "nhap a[" << i + 1 << "]";
  13. cin >> a[i];
  14. }
  15. int min = a[1];
  16. for (int i = 0; i < n; i++) {
  17. if (min > a[i]) {
  18. min = a[i];
  19. }
  20. }
  21. int max = a[n - 1];
  22. for (int i = 0; i < n; i++) {
  23. if (max < a[i]) {
  24. max = a[i];
  25. }
  26. }
  27. cout << min << " " << max;
  28. system("pause");
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement