Answer to Question #28451 in C++ for mohd azman samer
write c++ program to sort the number in ascending order.
9,2,5,10,1,7,4
1
2013-04-15T11:27:08-0400
#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;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment