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....


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];


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

reverse(a, 5);


  • : #include
    : #include
    Why are you using [b]iostream.h[/b] AND [b]stdio.h[/b]? And iostream.h has been replaced ages ago. It's just [b]iostream [/b]now.

    : for (i=1; i<=k; i++)
    : { cin>>a[i]; }
    If your function is supposed to reverse the data, why does it input the data? A function should do one thing, and do it well.

    : for (j=1; j<=k; j++)
    Arrays in C++ start at 0, not 1

    : void main()
    [b]main()[/b] is not and never has had a [italic]void[/italic] definition. It is [italic]int[/italic].

    Why don't you post your code in CODE tags so we can read it properly? Assuming of course you formatted it properly in the first place.

    Last, you can easily debug your own code by outputting variable and equation values at key places so you can see if the values are correct.
Sign In or Register to comment.

Howdy, Stranger!

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


In this Discussion