Question #28451

write c++ program to sort the number in ascending order.
9,2,5,10,1,7,4

Expert's answer

#include <iostream>

using namespace std;

int main() {

int a[7] = {9, 2, 5, 10, 1, 7, 4};

int n = 7;

//Bubble sort

for (int i = 0; i < n; i++)

for (int j = 0; j < n-1; j++)

& if (a[j] > a[j+1]) swap(a[j], a[j+1]);

for (int i = 0; i < n; i++)

& cout << a[i] << " ";

cout << endl;

}

using namespace std;

int main() {

int a[7] = {9, 2, 5, 10, 1, 7, 4};

int n = 7;

//Bubble sort

for (int i = 0; i < n; i++)

for (int j = 0; j < n-1; j++)

& if (a[j] > a[j+1]) swap(a[j], a[j+1]);

for (int i = 0; i < n; i++)

& cout << a[i] << " ";

cout << endl;

}

## Comments

## Leave a comment