63 063
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #3312 in C++ for mukunda

Question #3312
Write a program to arrange the given numbers in ascending order using sort function & display them using display function.
Expert's answer
#include <iostream>
using namespace std;

void sort (int numbers[], int size)
{
for (int i = 0; i < size-1; ++i) {
& for (int j = i+1; j < size; ++j) {
& if (numbers[i] > numbers[j]) {
& int temp = numbers[i];
& numbers[i] = numbers[j];
& numbers[j] = temp;
& }
& }
}
}

void display (int numbers[], int size)
{
for (int i = 0; i < size; ++i) {
& cout << numbers[i] << " ";
}
cout << endl;
}

int main()
{
int numbers[] = { 10, 20, 5, 12, -8, 17 };
int size = sizeof(numbers) / sizeof(int);

display (numbers, size);
sort (numbers, size);
display (numbers, size);

return 0;
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions