How to reverse an array of a table? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to reverse an array of a table?

Reversing an array with explanation, mainly the looping part?

5th Mar 2017, 2:52 PM
Abdul Khan
1 Answer
+ 1
suppose array is of n elements... int a[10],n,t; // read n here for(int i=0;i<n/2;i++) //1 { t=a[i]; //2 a[i]=a[n-i]; //3 a[n-i]=t; //4 } the reversing is done by swapping first and last element, second and second last element, like that... there for loop only need to work upto half of the array in 2,3 and 4 swapping is being done...
5th Mar 2017, 3:06 PM
vishnu
vishnu - avatar