Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- void main()
- {
- int n,i=0;
- bool flag;
- setlocale(LC_ALL, "rus");
- cout<<"Введите количество переменных N: ";
- cin>>n;
- if(n<=0)
- {
- cout<<"Размерность массива должна быть больше 0!!!"<<endl;
- system("pause");
- }
- else
- {
- int* mas = new int[n + 1];
- cout << "Введите А: ";
- cin >> mas[n];
- cout<<endl;
- for (i=0; i < n; i++)
- {
- cout<<"a["<<i<<"] -> ";
- cin>>mas[i];
- cout<<endl;
- }
- do
- {
- flag = 1;
- for (i = 0; i < n; i++)
- if (mas[i] > mas[i + 1])
- {
- flag = 0;
- swap(mas[i], mas[i + 1]);
- }
- } while (!flag);
- for (i = 0; i < n+1; i++)cout <<" "<<mas[i];
- cout<<endl;
- delete[]mas;
- system("pause");
- }
- }
Add Comment
Please, Sign In to add comment