-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorting_using_bubblesort.c
58 lines (43 loc) · 1.15 KB
/
sorting_using_bubblesort.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
53
54
55
56
57
58
/* *************************************************************
* Sorting data using bubblesort method
* ************************************************************ */
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define SIZE 100
int main()
{
int list[SIZE];
int a,b, temp;
/* **** seeding the randomizer **** */
srand((unsigned) time(NULL));
/* *** Build and display random numbers *** */
printf("The %d numbers generated randomly and unsorted are: \n", SIZE);
for (a = 0; a < SIZE; a++)
{
list[a]=rand() %100 +1;
printf("%0d \t",list[a]);
}
putchar('\n');
/* *** Performing the bubblesort *** */
for ( a = 0; a < SIZE-1; a++)
{
for (b = a+1 ;b < SIZE;b++)
{
if (list[a]>list[b])
{
temp=list[a];
list[a]=list[b];
list[b]=temp;
}
}
}
/* *** Display the sorted values *** */
printf("%d randomly generated value, sorted are: \n",SIZE);
for (a = 0; a < SIZE; a++)
{
printf("%4d",a);
}
putchar('\n');
return (0);
}