-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathde01.cpp
118 lines (100 loc) · 2.19 KB
/
de01.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int a[100][100];
int m,n;
//Nhap mang
void Nhapmang(int x[100][100], int &m, int &n)
{
do{
printf("Nhap m va n: ");
scanf("%d%d",&m,&n);
}while(m<=0||n<=0);
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
printf("x[%d][%d]=",i,j);
scanf("%d", &x[i][j]);
}
}
}
//Xuatmang
void Xuatmang(int x[100][100], int m, int n){
printf("\nMang vua nhap la: \n");
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
printf("%d\t", a[i][j]);
}
printf("\n");
}
}
//Sapxepmang
void Sapxep(int x[100][100], int m, int n){
int i,j,k;
for(i=0;i<m;i++){
for(j=0;j<n;j++){
for(k=j+1;k<n;k++){
if(a[j][i] > a[k][j]){
int temp = a[j][i];
a[j][i] = a[k][i];
a[k][i] = temp;
}
}
}
}
Xuatmang(x,m,n);
}
//
//Tinh tong phan tu nguyen to chia het cho 3
void Sum(int a[100][100], int m, int n){
int tong=0;
//duyet hang cua ma tran
for(int i =0; i< m; i++){
//duyet cot cua ma tran
for(int j =0 ; j<n; j++){
tong += a[i][j];
}
}
printf("\nTong cac phan tu trong ma tran la: %d", tong);
}
int main(){
int key;
while(true)
{
system("cls");
printf("***************************************************\n");
printf("** MANG 2 CHIEU **\n");
printf("** 1. Nhap xuat mang 2 chieu **\n");
printf("** 2. Sap xep mang tang dan **\n");
printf("** 3. Tinh tong phan tu nt chia het cho 3 **\n");
printf("** 0. Thoat **\n");
printf("***************************************************\n");
printf("\n \t\t AN PHIM CHON: ");
scanf("%d",&key);
switch(key)
{
case 1:
system("cls");
Nhapmang(a,m,n);
Xuatmang(a,m,n);
getch();
break;
case 2:
system("cls");
Sapxep(a,m,n);
getch();
break;
case 3:
system("cls");
Sum(a,m,n);
getch();
break;
case 0:
exit(1);
default:
printf("\nkhong co chuc nang nay!");
printf("\nBam phim bat ky de tiep tuc!");
getch();
break;
}
}
}