# Answer to Question #28451 in C++ for mohd azman samer

Question #28451

write c++ program to sort the number in ascending order.

9,2,5,10,1,7,4

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;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment