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
1
Expert's answer
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS