Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Bài tập 6: Viết hàm tráo đổi giá trị của 2 số. Sau đó thực hiện sắp xếp dãy số cho trước.
- #include <iostream>
- using namespace std;
- void exchange(int &a, int &b)
- {
- int t;
- t = a;
- a = b;
- b = t;
- }
- int main()
- {
- int x, y;
- cout << " Enter - x , y: ";
- cin >> x >> y;
- cout << "the two - digit order when unchanged is : " << x << " ; " << y << endl;
- exchange(x, y);
- cout << "the two - digit order when unchanged is : " << x << " ; " << y << endl;
- int arr[8] = { 1, 3, 2, 4, 7, 5, 8, 6 };
- cout << "Serial number when not sorted : " << endl;
- for (int i = 0; i < 8; i++)
- {
- cout << arr[i] << " , ";
- }
- cout << endl;
- for (int i = 0; i < 7; i++)
- {
- for (int j = i + 1; j < 8; j++)
- {
- if (arr[i] > arr[j])
- {
- exchange(arr[i], arr[j]);
- }
- }
- }
- cout << "The sequence of numbers when shorted from baby to large is : " << endl;
- for (int i = 0; i < 8; i++)
- {
- cout << arr[i] << " , ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement