FANDOM


#include <stdio.h>
#define ARRAYSIZE 100
 
int reversefunction(int x[], int y[], int num)
{
  int counter;
  int countbackwards;
  countbackwards = num;
  counter=0;
  while (counter <= num)
    {
	/* y will get what's in x backwards */
      y[countbackwards] = x[counter];
	/*printf("%d\n", x[counter]);*/
	 counter++;
	 countbackwards--;
	}
  return y[num];
}
 
int main (void)
{
  int howmany;
  int counter, num;
  int arrayinput;
  /*Ask the user how many numbers the array will hold*/
  printf("How many numbers in the array?\n");
  scanf("%d", &howmany);
  /*Array addresses start at 0*/
  int x[ARRAYSIZE];
  int y[ARRAYSIZE];
  counter=0;
 
  printf("Enter array numbers:\n");
 
  while(counter < howmany)
  {
    scanf("%d", &arrayinput);
	x[counter] = arrayinput;
	counter++;
  }
 
  num = howmany-1;
 
  printf("The array forwards is:\n");
  counter=0;
  while( counter < howmany )
   {
     printf("%d\n", x[counter]);
	 counter++;
   }
 
  printf("The array backwards is:\n");
  reversefunction(x, y, num);
 
  counter=0;
  while( counter < howmany )
   {
     printf("%d\n", y[counter]);
	 counter++;
   }
  return 0;
}
 
 
</souce>