Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

A little help please

Name: Anonymous 2007-09-05 15:29 ID:so4w/yz5

void reverseHalves(int a[], int size)
{
    int i, t;

      if((size%2) != 0)  Size ODD
      {
        for(i=0;i<=((size/2)-1);i++)
        {
            t = a[i];
            a[i] = a[(size/2)+i+1];
            a[(size/2)+i+1] = t;
        }
      }

      if((size%2) == 0)  Size EVEN
      {
        for(i=0;i<=((size/2)-1);i++)
         {
              t = a[i];
              a[i] = a[(size/2)+i];
              a[(size/2)+i] = t;
          }
      }

    return;
}


This function swaps the halves of an array.

e.g.

1
2
3
4

comes out as:

3
4
1
2

I handed it in to my professor and he said he wants me to do it over using only one loop. The reason I used two loops in the first place because the program would crash when based on whether or not an odd/even amount of elements were present for the array. He said I could used a nested for loop, but I haven't been able to figure out how to create it.

Name: Anonymous 2007-09-05 16:09 ID:Heaven

>>14
The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. In the case of a well-known conversational programming language I have been told from various sides that as soon as a programming community is equipped with a terminal for it, a specific phenomenon occurs that even has a well-established name: it is called "the one-liners". It takes one of two different forms: one programmer places a one-line program on the desk of another and either he proudly tells what it does and adds the question "Can you code this in less symbols?" —as if this were of any conceptual relevance!— or he just asks "Guess what it does!". From this observation we must conclude that this language as a tool is an open invitation for clever tricks; and while exactly this may be the explanation for some of its appeal, viz. to those who like to show how clever they are, I am sorry, but I must regard this as one of the most damning things that can be said about a programming language.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List