title: Bubble sort Descending and Ascending in C won't sort
body: <p>I'm giving a user choices to whether sort the elements in ascending or descending order. I know my code can sorts the elements right but somewhere in main I think I'm making mistake in calling my function to print the ascending/descending element in their proper order. Or do I have to have another if statement like I have in the <code>bubble_sort</code> function? I need to make it so the Main function prints the final results to the user. Here's the output I'm getting: 
  <strong><em>Enter number of elements
  3
  Enter 3 integers
  43
  7
  90
  Enter sort order
  Please enter A for ascending or D for descending order
  d
  Sorted list in descending order:
  43
  7
  90</em></strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void bubble_sort(long [], char n);
  
  int main()
  {
      long array[100], n, c;
  
      printf("Enter number of elements\n");
      scanf("%ld", &amp;n);
  
      printf("Enter %ld integers\n", n);
      for (c = 0; c &lt; n; c++)
          scanf("%ld", &amp;array[c]);
  
      printf("Enter sort order\n");
      fflush(stdin);
      printf("Please enter A for ascending or D for descending order\n");
      scanf("%ld", &amp;n);
      bubble_sort(array, n);
      printf("Sorted list in descending order:\n");
      for ( c = 0 ; c &lt; n ; c++ )
      {
          printf("%ld\n", array[c]);
      }
      fflush(stdin);
      getchar();
      return 0;
  }
  
  void bubble_sort(long list[], char n)
  {
      long c, d, temp;
  
      if(n=='a' || n=='A')
      {
          for (c = 0 ; c &lt; ( n - 1 ); c++)
          {
              for (d = 0 ; d &lt; n - c - 1; d++)
              {
                  if (list[d] &gt; list[d+1])
                  {
                      temp = list[d];
                      list[d] = list[d+1];
                      list[d+1] = temp;
                  }
              }
          }
      }
      if(n=='d' || n=='D')
      {
          long c, d, temp;
  
          for (c = 0 ; c &lt; ( n - 1 ); c++)
          {
              for (d = 0 ; d &gt; n - c - 1; d++)
              {
                  if (list[d] &lt; list[d+1])
                  {/* Swapping */
                      temp = list[d];
                      list[d] = list[d+1];
                      list[d+1] = temp;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> Here I added a swap function just so the ascending/descending logic is more efficient. But I seem to mixed up use of the variables which I think is a big problem. Would anyone point out and help me understand where and why I'd need to use those variables? Thanks much!  </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void bubble_sort(int list[], int n, char c);
  void swap(int x, int y, int array[]);
  int main()
  {
      int array[100], j, i;
      char c;
      printf("Enter number of elements\n");
      scanf("%d", &amp;j);
  
      printf("Enter %d integers\n", j);
      for (i = 0; i &lt; j; i++)
          scanf("%d", &amp;array[i]);
  
      printf("Please enter A for ascending or D for descending order\n");
      scanf("%s", &amp;c);
  
      bubble_sort(array, j, i);
      printf("Sorted list in descending order:\n");
      for (i = 0 ; i &lt; j ; i++ )
      {
          printf("%d\n", array[i]);
      }
      getchar();
      return 0;
  }
  
  void bubble_sort(int list[], int n, char c)
  {
      int i, j;
  
      if(c=='a' || c=='A'){
          for (i = 0; i &lt; (n - 1); i++){
              for (j = 0; j &lt; (n - i) - 1; j++){
                  if (list[i] &gt; list[j])
                  {
                      swap(i, j, list);                }
              }
          }
      }
      if(c=='d' || c=='D') {
          for (i = 0 ; i &lt; ( n - 1 ); i++) {
              for (j = 0 ; j &gt; (n - i) - 1; j++) {
                  if (list[i] &lt; list[j])
                  {
                      swap(i, j, list);
                  }
              }
          }
      }
  }
  
  void swap(int x, int y, int array[])
  {
      int hold; //temp hold a number
  
      hold = array[x];
      array[x] = array[y];
      array[y] = hold;
  }
  </code></pre>