Find Reverse of an Array in C Using Functions
This article will demonstrate how to create a C program that uses a function to reverse an array. For instance, if "arr" is an array of three numbers like in:
Then, by reversing the array we will have:
In C, you may reverse an array in four different ways: with a for loop, pointers, recursion, or by writing a function.
?nter size of array: 3 ?nter the elements of the array: 1 2 3 After reversing the array: 3 2 1 .................................... Process executed in 1.22 seconds Press any key to continue.
In the above example of a program in C, we have demonstrated how we can use function to reverse an array. We have created a user defined function reverse which takes the array and the size of the array as parameter and creates a tmp variable to swap the numbers.
5 4 3 2 1 ............. Process executed in 2.12 seconds Press any key to continue.
In the above example of a program in C, reading the items from both ends of the array and swapping them can be used to build a linear in-place algorithm, as shown in the example.
5 4 3 2 1 .................... Process executed in 1.22 seconds Press any key to continue.
Another is a recurring system that puts the elements in a call stack before returning them to the same members in the correct order at the end of the repetition.
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week