Answer:
void reverse(char dest[], char source[], int size)
{
for(int i=0;i<size;i++)//using for loop.
{
dest[i]=source[i];//assigning each element of source array to dest array.
}
int s=0,e=size-1;//initializing two elements s with 0 and e with size -1.
while(s<e){
char t=des[s]; //SWAPPING
dest[s]=dest[e]; //SWAPPING
dest[e]=t; //SWAPPING
s++;
e--;
}
}
Step-by-step explanation:
I have used while loop to reverse the array.I have initialize two integer variables s and e with 0 and size-1.Looping until s becomes greater than e.
It will work as follows:
first s=0 and e=0.
dest[0] will be swapped with dest[size-1]
then s=1 and e=size-2.
then des[1] will be swapped with dest[size-2]
and it will keep on going till s is less than e.