Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- University : HTI
- CodeName : Write a program to sort array ascending
- SubjectName : Programming Structure
- SubjectCode : csc121
- Group : https://www.facebook.com/groups/1421186571334814
- event : Ready to final
- */
- #include "stdafx.h"
- #include "iostream"
- using namespace std;
- int main(void)
- {
- int x[5], h;
- // Insert [x] Array
- for(int i = 0; i < 5; i++)
- {
- cout << "X[" << (i+1) << "][" << (i+1) << "]= ";
- cin >> x[i];
- }
- // Sort the array
- for(int i = 0; i < 4; i++)
- {
- for(int n = i+1; n < 5; n++)
- {
- // if you want to sort it descending make x[i] < x[n]
- if(x[i] > x[n]){
- h = x[i];
- x[i] = x[n];
- x[n] = h;
- }
- }
- }
- // print Array
- for(int i = 0; i < 5; i++)
- {
- cout << " " << x[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement