Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int a[50], n, i, aux;
- cout << "N = ";
- cin >> n;
- cout << endl;
- for ( i = 1; i <= n; i++ ) {
- cout << "a["<<i<<"] = ";
- cin >> a[i];
- }
- cout << endl;
- cout << "Tabloul introdus: " << endl << endl;
- for ( i = 1; i <= n; i++ ) {
- cout << a[i] << " ";
- }
- cout << endl << endl;
- int ok;
- int j;
- do {
- ok = 1;
- for ( i = 0; i < n; i++ )
- for ( j = i+1; j <= n; j++ )
- if ( a[i] < a[j] ) {
- aux = a[j];
- a[j] = a[i];
- a[i] = aux;
- ok = 0;
- }
- }
- while ( ok==0 );
- do {
- ok = 1;
- for ( i = 1; i <= n; i++ )
- for ( j = i+1; j <= n; j++ )
- if ( a[i] > a[j] ) {
- aux = a[j];
- a[j] = a[i];
- a[i] = aux;
- ok = 0;
- }
- }
- while ( ok==0 );
- cout << "Tabloul sortat: " << endl;
- for ( i = 1; i <= n; i++ ) {
- cout << a[i] << " ";
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement