reversing the order of array - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

reversing the order of array

i am really fed up. please help me where i am getting wrong. i just cant get my mistake..
for input 1,2,3,4,5 its giving 5,2,3,4,1....

#include
#include

void reverse(int a[], int k)
{


int j,i,t;
for (i=1; i<=k; i++)
{ cin>>a[i]; }

for (j=k; j>=k/2; j--)
{ t=a[j];

a[j]=a[k-j+1];

a[k-j+1]=t;
}
for (j=1; j<=k; j++)
{cout<<a[j]<<"
"; }
}
void main()
{
int a[5];


reverse(a, 5);
}
Sign In or Register to comment.