answersLogoWhite

0

Sorting can be done by taking the first integer value and comparing it by the rest of the elements in the array . The large or small number can be pushed swapped with its large or small (vice versa) as per preference and the array will be sorted out .

  1. void ascending() {
  2. int x = 0;
  3. int temp = 0;
  4. float fUserArray[10] = {0};
  5. for(x=0; x<10; x++) {
  6. printf("\nPlease enter a number: ");
  7. scanf("%f", &fUserArray[x]);
  8. }//end for loop
  9. for(x=0;x<10; x++) {
  10. if(fUserArray[x] > fUserArray[x+1]) {
  11. temp = fUserArray[x];
  12. fUserArray[x] = fUserArray[x+1];
  13. fUserArray[x+1] = temp;
  14. }//end if
  15. }//end for loop
  16. printf("\nYour numbers in ascending order are:");
  17. for(x=0;x<10;x++){
  18. printf("\n%.2f", fUserArray[x]); }//end for
  19. }//End ascending function
  20. /**********************************/
  21. /*Function definition--descending */
  22. void descending() {
  23. int x = 0;
  24. int temp = 0;
  25. float fUserArray[10] = {0};
  26. for(x=0;x<10;x++) {
  27. printf("\nPlease enter a number: ");
  28. scanf("%f", &fUserArray[x]);
  29. }//end for loop
  30. for(x=0;x<10;x++) {
  31. if(fUserArray[x] < fUserArray[x+1]){
  32. temp = fUserArray[x];
  33. fUserArray[x] = fUserArray[x+1];
  34. fUserArray[x+1] = temp;
  35. }//end if
  36. }//End for loop
  37. printf("\nYour numbers in descending order are:");
  38. for(x=0;x<10;x++) {
  39. printf("\n%.2f", fUserArray[x]);
  40. }//end for loop
  41. }//end descending function
User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Sort array in ascending descending order in python?

Using sorted(array,reverse=True)


How use array sort program in c sharp?

Assume an array of integers (size &gt; 0) to be sorted in descending order. And the values have been populated already: const int size = 50; //by changing the value here int[] array = new int[](); // omit the initialization of array Array.Sort(array); // array will be changed with ascending order Array.Reverse(array); // change from ascending to descending NOTE: Array.Sort() and Array.Reverse() are 2 of the functions in the class library. We do not care the algorithm being used within the functions, just the result. Also noted that the these 2 functions do change the content of the source array. It may not be what you want


How do you sort variable in ascending or descending order both in php?

Assuming that the values are stored in an array, you can use the php function sort($array) to sort ascending, and rsort to sort descending. The following link gives a table that lists all of the built in PHP sort functions: http://php.net/manual/en/array.sorting.php


What is the most efficient way to find the median of an unsorted array of numbers?

One efficient way to find the median of an unsorted array of numbers is to first sort the array in either ascending or descending order, then determine the middle value as the median.


C plus plus array accepting number descending and ascending?

std::array&lt;int, 10&gt; a {5, 7, 4, 2, 3, 9, 0, 8, 6, 1}; std::sort (a.begin(); a.end()); // ascending (implies default comparison operator: std::less_than&lt;int&gt;()) std::sort (a.begin(); a.end(); std::greater_than&lt;int&gt;()); // descending


How can the keyword "sorting" be implemented in pseudo code to arrange the elements of an array a of integers in ascending order?

To implement the keyword &quot;sorting&quot; in pseudo code to arrange the elements of an array a of integers in ascending order, you can use the following algorithm: Start by iterating through the array a from the first element to the second-to-last element. Compare each element with the next element in the array. If the current element is greater than the next element, swap their positions. Continue this process until the entire array is sorted in ascending order. Here is a simple example of pseudo code for implementing the sorting algorithm: for i from 0 to length(a) - 1 do for j from 0 to length(a) - i - 1 do if aj aj 1 then swap(aj, aj 1) end if end for end for This pseudo code represents a basic implementation of a sorting algorithm to arrange the elements of an array in ascending order.


Sort the array of integers in Descending order?

Make use of Java's robust library: // filled with various ints int[] a; // temporary variable for swapping values int temp; // sort with fast, built-in algorithm java.util.Arrays.sort(a); // reverse the array for( int i = 0; i &lt; a.length/2; ++i ) { temp = a[i]; a[i] = a[a.length - i - 1]; a[a.length - i - 1] = temp; } Obviously, if you're concerned with execution speed you could write your own sort method which would sort into descending order instead of ascending order (perhaps by modifying Java's sort algorithm).


What is Jagged Array in C?

A Jagged array is an array of arrays. You can initialize a jagged array as &minus; int[][] scores = new int[2][]{new int[]{92,93,94},new int[]{85,66,87,88}}; Where, scores is an array of two arrays of integers - scores[0] is an array of 3 integers and scores[1] is an array of 4 integers.


How do you display 15 numbers in an ascending order using an array?

Sort the array then traverse the array, printing the element values as you go.


What is the value of the kth smallest element in the given array?

The value of the kth smallest element in the array is the kth element when the array is sorted in ascending order.


How do you arrange 4 numbers in ascending order without array?

addends


What is an associative array?

An associative array is one of a number of array-like data structures where the indices are not limited to integers.