SHOW:
|
|
- or go back to the newest paste.
| 1 | #include<stdio.h> | |
| 2 | #include<conio.h> | |
| 3 | #include<limits.h> | |
| 4 | #include<stdlib.h> | |
| 5 | ||
| 6 | long int n; | |
| 7 | long int arr[10000]; | |
| 8 | ||
| 9 | void ini_random_number(); | |
| 10 | void print(); | |
| 11 | void bubble_sort(); | |
| 12 | ||
| 13 | int main() | |
| 14 | {
| |
| 15 | ||
| 16 | printf("How many numbers do u want? : ");
| |
| 17 | scanf("%d",&n);
| |
| 18 | ||
| 19 | ini_random_number(); | |
| 20 | bubble_sort(); | |
| 21 | print(); | |
| 22 | //kgetch(); | |
| 23 | return 0; | |
| 24 | ||
| 25 | } | |
| 26 | void bubble_sort() | |
| 27 | {
| |
| 28 | int k,j,t,x; | |
| 29 | k=n; | |
| 30 | ||
| 31 | while(k!=0) | |
| 32 | {
| |
| 33 | t=0; | |
| 34 | for(j=1;j<= k-1;j++) | |
| 35 | {
| |
| 36 | if(arr[j]>arr[j+1]) | |
| 37 | {
| |
| 38 | x=arr[j]; | |
| 39 | arr[j]=arr[j+1]; | |
| 40 | arr[j+1]=x; | |
| 41 | t=j; | |
| 42 | } | |
| 43 | } | |
| 44 | k=t; | |
| 45 | } | |
| 46 | } | |
| 47 | void ini_random_number() | |
| 48 | {
| |
| 49 | int i; | |
| 50 | //randomize(); | |
| 51 | printf("\n\nRandom numbers are :\n\n ");
| |
| 52 | ||
| 53 | for(i=1;i<=n;i++) | |
| 54 | {
| |
| 55 | arr[i]=rand()%1000; | |
| 56 | ||
| 57 | printf(" %d ",arr[i]);
| |
| 58 | } | |
| 59 | arr[0]=INT_MIN; | |
| 60 | } | |
| 61 | void print() | |
| 62 | {
| |
| 63 | int i; | |
| 64 | printf("\n\nAfter Bubble Sorting :\n\n ");
| |
| 65 | for(i=1;i<=n; i++) | |
| 66 | {
| |
| 67 | printf(" %d ",arr[i]);
| |
| 68 | } | |
| 69 | ||
| 70 | } |