Advertisement
_liemnguyen

Câu 3

Feb 14th, 2020
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. int n = 3,
  7. a=0,
  8. b=0,
  9. c=0;
  10. int array[n]={0};
  11.  
  12. cout<<"So luong phan tu mang ( n >= 1 ): ";
  13. cin>>n;
  14. if(n <1 ){
  15. return 0;
  16. }
  17.  
  18. int t;
  19. for(int i = 0;i<n;i++){
  20. cout<<"array["<<i<<"]: ";
  21. cin>>t;
  22. while(t<1||t>1000){
  23. cout<<"Nhap lai array["<<i<<"]: ";
  24. cin>>t;
  25. }
  26. array[i]=t;
  27. }
  28.  
  29. a = array[0],
  30. b=array[1],
  31. c=array[2];
  32.  
  33. for(int i = 3;i<n;i++){
  34. if (array[i]> a)
  35. a = array[i];
  36. if (array[i]> b)
  37. b = array[i];
  38. if (array[i]> c)
  39. c = array[i];
  40.  
  41. }
  42.  
  43. cout<<a<<" "<<b<<" "<<c;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement