-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab7b2.c
More file actions
55 lines (53 loc) · 1.04 KB
/
lab7b2.c
File metadata and controls
55 lines (53 loc) · 1.04 KB
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
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
// khai bao mang co 100 phan tu
// khoi tao sinh to ngau nhien bang thoi gian
// sinh to ngau nhien gan vao bang
// In mảng thành 10 hàng 10 cột
// sap xep bang Bubble Sort
int main()
{
//buoc1
int a[100];
//buoc2
srand(time(NULL));
//buoc3
for(int i =0; i <100; i++)
{
a[i] = rand() %1001;
}
//buoc4
for(int i =0; i <100;i++)
{
printf("%4d ", a[i]);
if((i+1)%10 == 0)
{
printf("\n");
}
}
//buoc5
for(int i = 0; i<100 -1;i++)
{
for(int j = 0; j<100 -i-1;j++)
{
if(a[j]<a[j + 1])
{
int temp = a[j];
a[j]=a[j+1];
a[j+1] =temp;
}
}
}
printf("\n mang sau khi duoc sap xep: \n");
for(int i=0; i<100; i++)
{
printf("4%d ", a[i]);
if((i+1)%10 == 0)
{
printf("\n");
}
}
printf("\n");
return 0;
}