Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //XCODE
- #include <iostream>
- int main(int argc, const char * argv[]) {
- long n,k,buf;
- bool ch;
- bool per = false;
- std::srand(std::time(0));
- std::cout<<"Input N:";
- std::cin>>n;
- std::cout<<"If you want random generation - input 1\n If you want hand-made generation - input 0\n";
- std::cin>>ch;
- long* mas = new long[n];
- for(int i = 0; i<n; i++){
- switch (ch) {
- case 0:
- std::cin>>mas[i];
- break;
- case 1:
- mas[i] = rand();
- break;
- default:
- break;
- }
- }
- for (int i = 0; i<n; i++) {
- std::cout<<mas[i]<<" ";
- }
- std::cout<<"\n";
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n-i-1; j++) {
- if (mas[j] > mas[j+1]) {
- long b = mas[j];
- mas[j] = mas[j+1];
- mas[j+1] = b;
- per = true;
- }
- }
- if(per==false){
- break;
- }
- }
- for (int i = 0; i<n; i++) {
- std::cout<<mas[i]<<" ";
- }
- delete[] mas;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment