Reverse order of elements of an array Assignment Help

Assignment Help: >> Algorithms for Problem Solving >> Reverse order of elements of an array

Reverse order of elements of an array

 Reverse order of element of an array means the value of first position of an array becomes the last element of an array and second element of an array becomes the second element of an array from last and so on.

Example:

Suppose we take the 10 arrays element, which is given below:

Array location:   a[0]        a[1]        a[2]        a[3]        a[4]        a[5]        a[6]        a[7]        a[8]        a[9]

Element:              1              3              2              4              5              7              8              5              9              7

After reversing:                7              9              5              8              7              5              4              2              3              1

Algorithm:

Step1: Start

Step 2: Take the values and store the values of the variable in an array with elements

a[0],a[1],a[2],a[3],...................,a[n]. (Because array starts from 0)

Step 3: Computer r, the number of exchange needed to reverse the array. Where r is

                 equal to integer value of ½.

Step 4: Exchange the element using the following statement.

                                temp = a[i];

                                a[i] = a[n-i+1];

                                a[n-i+1] =temp;

Step 5: Repeat step 4, r times increasing i by one.

Step 6: Print the reversed array element which is stored at the location a[0],a[1],.......

Step 7: Stop.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd