-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorting.c
52 lines (45 loc) · 1 KB
/
sorting.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*this program sort numbers in ascending order,
* where by the user enters the numbers
* Done by NDE YANICK CHE*/
#include<stdio.h>
#include<stdbool.h>
void bubblesort(int ,int array[]);
int main()
{
int i,length;
printf("enter the length of the array:");
scanf("%d",&length);
int array[length];
printf("enter the %d elements of the array\n",length);
for(i=0;i<length;i++)
{
scanf("%d",&array[i]);
}
bubblesort(length,array);
printf("the sorted elements in ascending order\n");
for(i=0;i<length;i++)
{
printf("%d\n",array[i]);
}
return 0;
}
void bubblesort(int length,int array[length])
{
bool issorted=false;
int i;
int swap;
while(!issorted)
{
issorted=true;
for(i=0;i<length;i++)
{
if(array[i]>array[i+1])
{
swap=array[i];
array[i]=array[i+1];
array[i+1]=swap;
issorted=false;
}
}
}
}