> looking at ur requierment, u can write in swap funtion like
What is wrong with using a temporary variable?
Not to mention the possibility of data corruption due to whatever way you machine handles arithmetic overflow and underflow.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
>arr[i] = arr[i] + arr[9-i] ;
>arr[9-i] = arr[i] - arr[9-i] ;
>arr[i] = arr[i] - arr[9-i]
That's clever and braindead at the same time. Unless of course you didn't discover that solution, in which case it's just braindead.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
> for( i = 0, j = 5; i<5; i++,j--)
The last element of the array is at index 4, not index 5
for ( i = 0 ; i < 5 ; i++ ) // going forwards
for ( i = 4 ; i >= 0 ; i-- ) // going backwards
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
you only need a single array as a parameter to swap(), and only use a single array within swap.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396