answersLogoWhite

0

Here's an example using a bubble sort. Note that this is not a very efficient sort, but it works weel enough with small data sets.

#include

#include

int main(void)

{

int item[100];

int a, b, t;

int count;

/* read in numbers */

printf("How many numbers? ");

scanf("%d", &count);

for(a = 0; a < count; a++)

scanf("%d", &item[a]);

/* now, sort them using a bubble sort */

for(a = 1; a < count; ++a)

for(b = count-1; b >= a; --b) {

/* compare adjacent elements */

if(item[ b - 1] > item[ b ]) {

/* exchange elements */

t = item[ b - 1];

item[ b - 1] = item[ b ];

item[ b ] = t;

}

}

/* display sorted list */

for(t=0; t

return 0;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

What are ascending factors?

Ascending means to write the factors from least to greatest.


How do you write 31 as an integer?

31 is an integer.


How can I write a program to display prime numbers from 1 to 100?

Write a function that implements an algorithm that checks to see if a particular integer is prime (returning a boolean). Write a program that uses that function on each number from 1 to 100, and if true, displays that number.


How do you write 001 as a fraction?

001 is the same as the integer 1 and so you would write it as 1.001 is the same as the integer 1 and so you would write it as 1.001 is the same as the integer 1 and so you would write it as 1.001 is the same as the integer 1 and so you would write it as 1.


What is 147000 as a fraction?

It is an integer, not a fraction, but if you must, you could write it as 147000/1.It is an integer, not a fraction, but if you must, you could write it as 147000/1.It is an integer, not a fraction, but if you must, you could write it as 147000/1.It is an integer, not a fraction, but if you must, you could write it as 147000/1.


How do you write 14494 as an integer?

-14,494


Write a program in vb to check whether a no is prime or not?

Function isPrime(ByVal n As Integer) As Boolean If n &lt; 2 Then Return False End If Dim sqrtn As Integer = Math.Sqrt(n) + 1 For i As Integer = 2 To sqrtn If (n Mod i) = 0 Then Return False End If Next Return True End Function


Can you write a program without specifying the prototype of any function?

You can write a program without specifying its prototype when the function returns an integer.If the prototype is not mentioned the compiler thinks that the return type of the function used is integer.When making program which return integer you can ignore writing the protoype.


Write a function prototype named test that accepts two parameters an integer and character and returns a float?

float test(int, char);


How do you write 5789 as an integer?

The number 5789 is already an integer.


How do you write 1440 as an integer?

1440 is an integer.


How do you write a mathematical function?

A mathematical function, f, is a mapping from an m-dimensional space, S (the domain), to an n-dimensional space, T, such that for every element in S there is one element in T. This may be denoted by f(x1, x2, ... , xm) = (y1, y2, ... , yn)