Skip to content

Latest commit

 

History

History
41 lines (36 loc) · 524 Bytes

C++升序、降序.md

File metadata and controls

41 lines (36 loc) · 524 Bytes

升序:

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int a[100],n;
	cin >> n;
	for (int i = 0;i < n;i ++){
		cin >> a[i];
	}
	sort(a + 0,a + n);
	for (int i = 0;i < n;i ++){
		cout << a[i] << " ";
	}
	return 0;
}

降序:

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int a[100],n;
	cin >> n;
	for (int i = 0;i < n;i ++){
		cin >> a[i];
	}
	sort(a + 0,a + n);
	for (int i = n - 1;i >= 0;i --){
		cout << a[i] << " ";
	}
	return 0;
}