Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://vk.com/evgenykravchenko0
- ___ ___ ___
- / /\ ___ / /\ / /\
- / /:/_ /__/\ / /:/_ / /:/_
- / /:/ /\ \ \:\ / /:/ /\ / /:/ /\
- / /:/ /:/_ \ \:\ / /:/_/::\ / /:/ /:/_
- /__/:/ /:/ /\ ___ \__\:\ /__/:/__\/\:\ /__/:/ /:/ /\
- \ \:\/:/ /:/ /__/\ | |:| \ \:\ /~~/:/ \ \:\/:/ /:/
- \ \::/ /:/ \ \:\| |:| \ \:\ /:/ \ \::/ /:/
- \ \:\/:/ \ \:\__|:| \ \:\/:/ \ \:\/:/
- \ \::/ \__\::::/ \ \::/ \ \::/
- \__\/ ~~~~ \__\/ \__\/
- ___
- /__/\ ___ ___
- \ \:\ / /\ / /\
- \ \:\ / /:/ / /:/
- _____\__\:\ /__/::\ /__/::\
- /__/::::::::\ \__\/\:\__ \__\/\:\__
- \ \:\~~\~~\/ \ \:\/\ \ \:\/\
- \ \:\ ~~~ \__\::/ \__\::/
- \ \:\ /__/:/ /__/:/
- \ \:\ \__\/ \__\/
- \__\/
- #include <iostream>
- #include <cmath>
- using namespace std;
- int Array_up (int size);
- int Array_down(int size);
- int main(int argc, const char * argv[])
- {
- int choice;
- int size;
- cout << "How do you want to sort array? " << endl;
- cout << " 1) Ascending [example: 1,2,3,...,n]" << endl;
- cout << " 2) Descending [example: n,n-1,n-2,...,1]" << endl;
- cout << "Enter your choice : ";
- cin >> choice;
- if (choice == 1)
- {
- cout << "Enter size of array : ";
- cin >> size;
- Array_up(size);
- }
- else
- if (choice == 2)
- {
- cout << "Enter size of array : ";
- cin >> size;
- Array_down(size);
- }
- else
- exit(0);
- return 0;
- }
- //FUNC
- int Array_up(int size)
- {
- int a[size];
- int temp = 0;
- cout << "Enter elements of array :" << endl;
- for ( int i = 0; i < size; i++)
- {
- cout << "a[" << i << "] = ";
- cin >> a[i];
- }
- cout << "Initial array : ";
- for (int i = 0; i < size; i++)
- cout << " " << a[i];
- for ( int i = 0; i < size; i++)
- {
- for( int j = 1; j < size; j++)
- {
- if ( a[j] < a[j - 1])
- {
- temp = a[j];
- a[j] = a[j - 1];
- a[j - 1] = temp;
- }
- }
- }
- cout << "\nReceived array : ";
- for ( int i = 0; i< size; i++)
- cout << " " << a[i];
- }
- int Array_down(int size)
- {
- int a[size];
- int temp = 0;
- cout << "Enter elements of array :" << endl;
- for ( int i = 0; i < size; i++)
- {
- cout << "a[" << i << "] = ";
- cin >> a[i];
- }
- cout << "Initial array : ";
- for (int i = 0; i < size; i++)
- cout << " " << a[i];
- for ( int i = 0; i < size; i++)
- {
- for( int j = 1; j < size; j++)
- {
- if ( a[j] > a[j - 1])
- {
- temp = a[j];
- a[j] = a[j - 1];
- a[j - 1] = temp;
- }
- }
- }
- cout << "\nReceived array : ";
- for ( int i = 0; i< size; i++)
- cout << " " << a[i];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement