# Answer to Question #53765 in C++ for ysrao.sri

Question #53765

Write a program which accepts 10 integers in an array and then arrange the array in ascending

order.

order.

Expert's answer

#include <iostream>

using namespace std;

void Sort(int* arr, int size);

int main() {

int array[10];

cout<<"Enter 10 integer values : \n";

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

cin>>array[i];

cout<<"\nInitial array : ";

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

cout<<array[i]<<" ";

cout<<endl;

Sort(array, 10);

cout<<"\nArray on ascending order : ";

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

cout<<array[i]<<" ";

cout<<endl;

cin.clear();

cin.ignore(1000, '\n');

cin.get();

return 0;

}

void Sort(int* arr, int size)

{

int tmp;

for(int i = 0; i < size - 1; ++i) // i - number of passes

{

for(int j = 0; j < size - 1; ++j) // inner loop of passage

{

if (arr[j + 1] < arr[j])

{

tmp = arr[j + 1];

arr[j + 1] = arr[j];

arr[j] = tmp;

}

}

}

}

using namespace std;

void Sort(int* arr, int size);

int main() {

int array[10];

cout<<"Enter 10 integer values : \n";

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

cin>>array[i];

cout<<"\nInitial array : ";

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

cout<<array[i]<<" ";

cout<<endl;

Sort(array, 10);

cout<<"\nArray on ascending order : ";

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

cout<<array[i]<<" ";

cout<<endl;

cin.clear();

cin.ignore(1000, '\n');

cin.get();

return 0;

}

void Sort(int* arr, int size)

{

int tmp;

for(int i = 0; i < size - 1; ++i) // i - number of passes

{

for(int j = 0; j < size - 1; ++j) // inner loop of passage

{

if (arr[j + 1] < arr[j])

{

tmp = arr[j + 1];

arr[j + 1] = arr[j];

arr[j] = tmp;

}

}

}

}

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