Tuesday, July 28, 2009

C++ program to reverse 2 consecutive numbers in an array?

c++ program to reverse 2 consecutive numbers in an array. for example if the array is a[ ] = {2,4,6,8,10} , output should be 4, 2, 8, 6, 10

C++ program to reverse 2 consecutive numbers in an array?
swap(array, size)


{


for (i=0, swaps = 0; i%26lt; size; i += 2, swaps++)


{ temp = array[i];


array[i] = array[1+1];


array[i+1] = temp;


}


return (swaps);


}


No comments:

Post a Comment