FANDOM


#define ARRAYSIZE 100 /* so there is no magic number random size */
 
void reverse ( int a[], int b[], int c); /* a function to reverse the order */
 
int main(void)
{
 
   int x[ARRAYSIZE]; /* original array */
   int y[ARRAYSIZE]; /* new, reversed array */
   int i;
   int input;
   int maxnumber;
   int count;
 
/* get the numbers from the users */
   printf("When you want to stop giving me numbers put in -1\n");
   i=0; /* initializing */
   /* getting the first number */
   printf("Enter first number  ");
   scanf("%d",&input);
   x[i]=input;
   i++;
   /* a while loop to get the next numbers */
   while (input != -1)
   {
      printf("Enter next number   ");
      scanf("%d", &input);
      /* an if statement to check if you should exit */
      if (input == -1)
      {}
      else
      {
         x[i] = input;
         i++;
      }
   }
   /* set maxnumber so you can put it into your function */
   maxnumber = i;
 
   reverse(x, y, maxnumber); /* the function */
 
   /* printing your inputs to make sure the program is working */
   count = 0;
   printf("Your inputs are: ");
   while(count<maxnumber)
   {
      printf(" %d", x[count]);
      count++;
   }
   /* printing the inputs in reverse */
   count=0;
   printf("\nIn reverse: ");
   while(count<maxnumber)
   {
      printf(" %d", y[count]);
      count++;
   }
   printf("\n");
 
return 0;
}