-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaslkdkcsd.c
58 lines (57 loc) · 1 KB
/
aslkdkcsd.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
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
void bubblesort(int a[],int n)
{
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
swap(&a[j],&a[j+1])
}
}
}
}
void print(int a[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%d",a[i]);
}
printf("\n");
}
void main()
{
printf("enter the elements you want to print.....");
int n,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
a[i]=rand()%10;
}
printf("the elemnts are....")
for(i=0;i<n;i++)
printf("%d",a[i]);
printf("\n");
double total;
clock t1,t2;
t1=clock();
bubblesort(a,n);
t2=clock();
total=(double)(t2-t1)/CLOCKS_PER_SEC;
printf("the sorted array is.......");
printf(a,n);
printf("the time taken is ....\n%1f",total);
}