Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- int main(){
- std::cout << "Enter 3 numbers:" << std::endl;
- int array[3];
- const int n = 3;
- for(int i = 0; i < n; i++) {
- std::cin >> array[i];
- }
- /* basic bubble sort for educational purposes
- * Replace with std::sort for production code
- */
- for(int i = n; i > 0; i--) {
- for(int j = 0; j < i - 1; j++) {
- if(array[j] > array[j+1]) {
- /* Replace with std::swap for production code */
- int hold = array[j];
- array[j] = array[j+1];
- array[j+1] = hold;
- }
- }
- }
- std::cout << "Ascending Array is:\n";
- for(int i = 0; i < 3; i++) {
- std::cout << array[i] << "\n";
- }
- std::cout << "Descending Array is:\n";
- for(int i = n - 1; i >= 0; i--) {
- std::cout << array[i] << "\n";
- }
- /* just for good measure */
- std::cout.flush();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement