Toggle navigation
Trang Chủ
Tính Năng
Đăng Ký / Đăng Nhập
Untitled 2019-12-10 12:27:15
#include
<iostream>
#include
<stdio.h>
using
namespace
std
;
// khai bao mang 2 chieu
int
m[
10
][
10
];
int
n;
// nhap ma tran
void
NhapMT(){
// nhap kich thuoc
cout
<<
"\n + Nhap ma tran:"
;
do
{
cout
<<
"\n Kinh thuoc n= "
;
cin
>>
n
;
if
(
n
<
2
||
n
>
10
)
cout
<<
"\n Nhap lai n!"
;
}
while
(
n
<
2
||
n
>
10
);
// nhap ma tran
cout
<<
"\n Nhap phan tu cua ma tran:"
;
for
(
int
i=
0
;i<
n
;i++)
for
(
int
j=
0
;j<
n
;j++)
{
cout
<<
"\n m["
<<i<<
"]["
<<j<<
"]= "
;
cin
>>
m
[i][j];
}
}
// In ma tran
void
InMT(){
cout
<<
"\n + In ma tran vua nhap: \n"
;
for
(
int
i=
0
;i<
n
;i++)
{
for
(
int
j=
0
;j<
n
;j++)
cout
<<
m
[i][j]<<
"\t"
;
cout
<<
"\n"
;
}
}
// Dem so chan co trong ma tran
void
DemSoChan(){
int
dem=
0
;
for
(
int
i=
0
;i<
n
;i++)
for
(
int
j=
0
;j<
n
;j++)
if
(
m
[i][j]%
2
==
0
)
dem++;
cout
<<
"\n + Dem so chan trong ma tran: "
<<dem;
}
// Tinh tong tung cot
void
TongCot(){
int
cot[
10
];
// chua gia tri tung cot
for
(
int
j=
0
;j<
n
;j++){
cot[j]=
0
;
for
(
int
i=
0
;i<
n
;i++)
cot[i]+=
m
[i][j];
}
cout
<<
"\n + Tong tung cot cua ma tran: "
;
for
(
int
i=
0
;i<
n
;i++)
cout
<<
"\n Cot "
<<i<<
" : "
<<cot[i];
}
// Ham kiem tra so nguyen to
int
TestNT(
int
a){
for
(
int
i=
2
;i<a;i++)
if
(a%i==
0
)
return
0
;
return
1
;
}
// Dem so nguyen to trong ma tran
void
InViTriSNT(){
cout
<<
"\n + In vi tri so nguyen to: "
;
for
(
int
i=
0
;i<
n
;i++)
for
(
int
j=
0
;j<
n
;j++)
if
(
TestNT
(
m
[i][j])==
1
)
cout
<<
"["
<<i<<
"]["
<<j<<
"], "
;
}
// Ham chinh
int
main(){
NhapMT
();
InMT
();
TongCot
();
DemSoChan
();
InViTriSNT
();
cout
<<
"\n - END - \n "
;
return
0
;
}
Public
Last Update: 2019-12-10 12:27:17