-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbubblesort.c
More file actions
44 lines (38 loc) · 734 Bytes
/
bubblesort.c
File metadata and controls
44 lines (38 loc) · 734 Bytes
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
//Bubble Sort
#include<stdio.h>
void bubsort(int arr[],int n)
{
int temp;
for (int i = 0; i < n-1; i++)
{
for (int j = 0; j < n-i-1; j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
int main()
{
int n;
printf("\nEnter the number of elements: ");
scanf("%d",&n);
int arr[n];
printf("\nEnter the elements: ");
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
bubsort(arr,n);
printf("\nAfter Sorting Elements are: ");
for (int i = 0; i < n; i++)
{
printf("%d ",arr[i]);
}
printf("\n");
return 0;
}