Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using std::cout;
- using std::cin;
- using std::endl;
- int main()
- {
- int n;
- cout << "Введите количество элементов массива : ";
- cin >> n;
- int * a = new int[n];
- for (int i = 0; i < n; i++) {
- cout << "[" << i + 1 << "]" << ": ";
- cin >> a[i];
- }
- cout << "Initial : " << endl;
- for(int i = 0; i < n; i++){
- cout << a[i] << " ";
- }
- cout << endl;
- for (int i=0; i<n; i++){
- for (int j=0; j<n-1; j++) {
- if (a[j]>a[j+1]){
- int k=a[j];
- a[j]=a[j+1];
- a[j+1]=k;
- }
- }
- }
- for (int i = 0; i < n; i++) {
- cout<<a[i]<<" ";
- }
- delete a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement