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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.