answersLogoWhite

0

#include "stdio.h"

#define ARRAY_SIZE 10

void fill(float* array, int size);

void spill(float* array, int size, char* delimiter);

void bubble_sort(float* array, int size);

void reverse(float* array, int size);

void swap(float* a, float* b);

int main(int argc, char* argv[]) {

float numbers[ARRAY_SIZE];

fill(numbers, ARRAY_SIZE);

bubble_sort(numbers, ARRAY_SIZE);

spill(numbers, ARRAY_SIZE, " ");

reverse(numbers, ARRAY_SIZE);

spill(numbers, ARRAY_SIZE, " ");

return 0;

}

void fill(float* array, int size) {

int i = 0;

while (i < size)

fscanf(stdin, "%f", array + (i++));

}

void spill(float* array, int size, char* delimiter) {

int i = 0;

while (i < size)

fprintf(stdout, "%f%s", array[i++], delimiter);

fputc('\n', stdout);

}

void bubble_sort(float* array, int size) {

int i, j;

for (i = 0; i < size; i++)

for (j = i; j < size; j++)

if (array[i] > array[j])

swap(array + i, array + j);

}

void reverse(float* array, int size) {

int i;

for (i = size / 2; i >= 0; i--)

swap(array + i, array + (size - (i + 1)));

}

void swap(float* a, float* b) {

float c = *a;

*a = *b;

*b = c;

}

fill gets the numbers from input

spill sends them to output

bubble sort will sort the array in ascending order

reverse will reverse the list so that it is in descending order

swap is used to swap two floats

You can change float to double or int depending on which datatype you want to use.

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What will be the program to arrange numbers stored in array in ascending order using pointers?

sorry


Write an Assembly language program which implements sorting algorithm both ascending and descending order and display those numbers with certain delay say of 5sec between successive displays?

das


C program to arrange the set of numbers in descending order?

main (){int i,j,a,n,number[30];printf ("Enter the value of N\n");scanf ("%d", &n);printf ("Enter the numbers \n");for (i=0; i


Algorithm and flow chart of the program for ascending and descending order of numbers?

Use a looping structure. The first step initialises a loop control variable, n, to zero. You then begin the loop by processing the nth element from the array (the process may be a simple print statement). You then increment n. Finally, you test the value of n; if it is less than 10 you start a new iteration of the loop, otherwise you proceed to the end of the flowchart.


Write a program for which give number in ascending number?

the following program will display all numbers given in the array in ascending order #include&lt;stdio.h&gt; void main() { int i,h,p; int numbers[10]={5,8,3,2,6,7,9,4,1,10}; for(p=0;p&lt;=8;p=p+1) { for(i=0;i&lt;=8;i=i+1) { if(numbers[i]&gt;numbers[i+1]) { a=numbers[i]; numbers[i]=numbers[i+1]; numbers[i+1]=a; } } } for(i=0;i&lt;=9;i=i+1) { printf("%d ",numbers[i]); } }


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


How can you write a c program to display numbers in ascending order in array?

I know how to do this and you need to know how to do this. Why don't you do your best at writing this program and if it does not work then ask for help. You will not learn anything if I give you the answer.


Demonstrate a program that prints numbers in ascending order.?

#include&lt;iostream&gt; int main() { for (int i=0; i&lt;100; ++i) std::cout&lt;&lt;i&lt;&lt;std::endl; }


Sort array in ascending descending order using function in c?

//C program for Arranging 5 Numbers in Ascending Order #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int a[5],i,j,t; clrscr(); printf("Enter 5 nos.\n\n"); for (i=0;i&lt;5;i++) scanf("%d",&amp;a[i]); for (i=0;i&lt;5;i++) { for(j=i+1;j&lt;5;j++) { if(a[i]&gt;a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } } } printf("Ascending Order is:"); for(j=0;j&lt;5;j++) printf("\n%d",a[j]); getch(); }


C program to fine the largest of 10 given number?

first sort the ten numbers in descending order and print the first number. That will be the largest no


Ascending order program for java?

public class BubbleSortAscendingOrderDemo { public static void main(String a[]) { //Numbers which need to be sorted int numbers[] = {23,5,23,1,7,12,3,34,0}; //Displaying the numbers before sorting System.out.print("Before sorting, numbers are "); for(int i = 0; i &lt; numbers.length; i++) { System.out.print(numbers[i]+" "); } System.out.println(); //Sorting in ascending order using bubble sort bubbleSortInAscendingOrder(numbers); //Displaying the numbers after sorting System.out.print("Before sorting, numbers are "); for(int i = 0; i &lt; numbers.length; i++) { System.out.print(numbers[i]+" "); } }


A C program using dynamic memory allocation to sort n names in ascending order?

Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.