educative.io

Educative

Exercise 1: Sorting Array in Ascending Order

int *sortAsc(int *arr, int n) {

//write code here
int love;

for (int i =0; i < n; i++){

for (int j =i+1; j< n; j++){

    if (*(arr+i) > *(arr+j)){

       love =*(arr+i);

       *(arr+i)=*(arr+j);

       *(arr+j)= love;
}

}

}
return arr;
}

how to call sortAsc(int *arr, int n) in main ()? any helps , welcome

1 Like

Hi @scott_mickel, Thank you for contacting the Educative team with your query!

You only have to write the function on the platform code block. The function is called in the main () by default.
Hope the answer to your query.
Please feel free to reply here if there is still some confusion also mention the link to the course and the lesson.
Hope you have an amazing learning experience on Educative!

sorry sir , but i mean in other IDES like eclipse c++ ?


Course: Learn C++ from Scratch - Free Interactive Course
Lesson: Exercise 2: Series Of Numbers - Learn C++ from Scratch

Hi @scott_mickel,

On any other Platform, you have to write the main function int main ().In that main function, you can call the required function. You properly have to initialize an array arr and the size n of the array which will be passed to the function sortAsc ().

Your main function should look like this:

Hope you get it
Thanks