-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path37.c
More file actions
32 lines (25 loc) · 609 Bytes
/
37.c
File metadata and controls
32 lines (25 loc) · 609 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
// Program to sort all elements of array.
#include <stdio.h>
int main() {
int a[50], n, i, j, temp;
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Enter array elements:\n");
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
printf("Sorted array:\n");
for (i = 0; i < n; i++) {
printf("%d ", a[i]);
}
return 0;
}