## Write a program that sorts an array in ascending order by passing the array to a function.

**So let’s Write Code:**

**Let’s build logic First:**

**Algorithm for code:**

**Step 1:**Start**Step 2:**Declare an array and variable.**Step 3:**Take inputs from user.**Step 4:**Passing array to function**Step 5:**Defining sort Function**void sort ( int x [ ])****Step 6:**Check Condition**if (x [i] > x [i+1])**to find minimum value for sort array in ascending order.**Step 7:**if value in x[i] > [i + 1] then exchange values, repeat this process until**i <=9.****Step 8:**Print elements**Step 9:**Finish Program

**Code:**

** Write a program that sorts an array in ascending order by passing the array to a function. **

```
#include<iostream>
using namespace std;
main()
{
int arr[10], i;
void sort(int []);
cout<<"Enter ten integer values in array\n";
for(i = 0; i<=9; i++)
{
cout<<"Enter value in element "<<i<<" ? ";
cin>>arr[i];
}
sort(arr);
cout<<"\nValues of array after sorting\n";
for(i = 0; i<=9; i++)
cout<<arr[i]<<" ";
}
```**// definition of sort() function**
void sort(int x[])
{
int i, u, temp;
u = 9;
while(u>=1)
{
i = 0;
while(i<u)
{
if(x[i] > x[i+1])
{
temp = x[i];
x[i] = x[i+1];
x[i+1] = temp;
}
i++;
}
u--;
}
}

**Hope You will learn Something. Happy Coding.**

###### Visit my YouTube Channel as Well๐ https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4

**Click on the below Links for more Programming Exercises: **

**Conditional Structure Exercises: **๐https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/

**Array Exercises: ๐**https://myustaadg.com/category/programming-exercises/arrays-exercises/