Bài tập C++: Xếp tăng xếp giảm

1. Đề bài sắp xếp dãy 10 số tự nhập từ bàn phím theo chiều tăng dần và giảm dần: Nhập số phần tử cần xếp, nhập dãy số cần sắp xếp và xuất ra...


1. Đề bài sắp xếp dãy 10 số tự nhập từ bàn phím theo chiều tăng dần và giảm dần:
Nhập số phần tử cần xếp, nhập dãy số cần sắp xếp và xuất ra 2 dãy số theo chiều tăng dần và giảm dần
Kết quả:
Nhap so phan tu: 10
Nhap phan tu thu [1]: 9
Nhap phan tu thu [2]: 8
Nhap phan tu thu [3]: 7
Nhap phan tu thu [4]: -9
Nhap phan tu thu [5]: 3
Nhap phan tu thu [6]: 2
Nhap phan tu thu [7]: 1
Nhap phan tu thu [8]: 5
Nhap phan tu thu [9]: 4
Nhap phan tu thu [10]: 0
Sap xep theo thu tu tang dan: -9 0 1 2 3 4 5 7  8 9
Sap xep theo thu tu giam dan: 9 8 7 5 4 3 2 1 0 -9
Press any key to continue . . .
2. Code sắp xếp theo chiều tăng dần và giảm dần:
#include <iostream>
using namespace std;
int main()
{
int a[15], i, j, n, temp;
  cout<<"Nhap so phan tu: ";
  cin>>n;
  for (i=1;i<n+1;i++)
    {
cout<<"Nhap phan tu thu ["<<i<<"]: ";
cin>>a[i];
    }
for (i = 1; i <=n-1; i++)
    for (j = i + 1; j < n+1; j++)
    {
     if (a[i] > a[j])
       {
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
        }
    }
cout<<"Xap xep theo thu tu tang dan: " ;
    for (i=1; i<=n; i ++)
cout<<a[i]<<"  ";
{
for (i = 1; i<=n-1;i++)
for (j = i+1; j <=n ; j++)
{
if (a[i] < a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
cout<<"\nXap xep theo thu tu giam dan: ";
    for (i=1; i<=n; i ++)
cout<<a[i]<<"  ";
cout<<endl;
system("pause");
}
}

COMMENTS

404Something Wrong!

The page you've requested can't be found. Why don't you browse around?

Tên

C Cộng Cộng,4,Danh Ngôn,2,Giải Trí,2,Lập Trình,4,Thủ Thuật,15,Thủ Thuật Blogger,5,Thủ Thuật Email,1,Thủ Thuật Facebook,1,Thủ Thuật Windows,7,Thủ Thuật Word,1,
ltr
item
Rắn Thông Thái: Bài tập C++: Xếp tăng xếp giảm
Bài tập C++: Xếp tăng xếp giảm
Rắn Thông Thái
https://ranthongthai.blogspot.com/2017/12/bai-tap-c-xep-tang-xep-giam.html
https://ranthongthai.blogspot.com/
http://ranthongthai.blogspot.com/
http://ranthongthai.blogspot.com/2017/12/bai-tap-c-xep-tang-xep-giam.html
true
532559575573683777
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content