-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting_array.c
More file actions
49 lines (37 loc) · 736 Bytes
/
sorting_array.c
File metadata and controls
49 lines (37 loc) · 736 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
45
46
47
48
49
#include <stdio.h>
int main(){
#define max 100
int arr[max], i ,j ,size , temp;
printf("Enter the size of the array: ");
scanf("%d", &size);
if (size<=0 || size > max)
{
printf("Error!, enter a number betwen 1 and %d.", max);
return 1;
}
printf("\n");
printf("pls fill the array:\n");
for ( i = 0; i < size; i++)
{
printf("T[%d]: ", i);
scanf("%d", &arr[i]);
}
for ( i = 0; i < size-1; i++)
{
for ( j = 0; j < size-1-i ; j++)
{
if (arr[j]>arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
printf("the array after sorting is:\n");
for ( i = 0; i < size; i++)
{
printf("%d\t", arr[i]);
}
return 0;
}