2015-07-28T15:01:56-04:00
Write a program which accepts 10 integers in an array and then arrange the array in ascending
order.
1
2015-07-30T02:21:31-0400
#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; } } } }
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