MargaritaOwl

Version2

Dec 29th, 2015
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1.  
  2. #include<iostream>
  3. #include<cstdlib>
  4. using namespace std;
  5. void main()
  6. {
  7. int n,i=0;
  8. bool flag;
  9. setlocale(LC_ALL, "rus");
  10.  
  11. cout<<"Введите количество переменных N: ";
  12. cin>>n;
  13.  
  14. if(n<=0)
  15. {
  16. cout<<"Размерность массива должна быть больше 0!!!"<<endl;
  17. system("pause");
  18. }
  19. else
  20. {
  21. int* mas = new int[n + 1];
  22.  
  23. cout << "Введите А: ";
  24. cin >> mas[n];
  25. cout<<endl;
  26.  
  27. for (i=0; i < n; i++)
  28. {
  29. cout<<"a["<<i<<"] -> ";
  30. cin>>mas[i];
  31. cout<<endl;
  32. }
  33.  
  34. do
  35. {
  36. flag = 1;
  37. for (i = 0; i < n; i++)
  38. if (mas[i] > mas[i + 1])
  39. {
  40. flag = 0;
  41. swap(mas[i], mas[i + 1]);
  42. }
  43. } while (!flag);
  44.  
  45. for (i = 0; i < n+1; i++)cout <<" "<<mas[i];
  46. cout<<endl;
  47. delete[]mas;
  48. system("pause");
  49. }
  50. }
Add Comment
Please, Sign In to add comment