-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathbubblesort.c
More file actions
30 lines (30 loc) · 758 Bytes
/
bubblesort.c
File metadata and controls
30 lines (30 loc) · 758 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
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[50], i, j, n, temp;
printf("Enter total number of elements to store: ");
scanf("%d", &n);
printf("Enter %d elements:", n);
for(i=0; i<n; i++)
scanf("%d", &arr[i]);
printf("\nSorting array using bubble sort technique...\n");
for(i=0; i<(n-1); i++)
{
for(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;
}
}
}
printf("All Array elements sorted successfully!\n");
printf("Array elements in ascending order:\n\n");
for(i=0; i<n; i++)
printf("%d ", arr[i]);
getch();
return 0;
}