基本信息
文件名称:C语言中的身份矩阵程序.docx
文件大小:15.64 KB
总页数:3 页
更新时间:2025-05-17
总字数:约1.24千字
文档摘要

C语言中的身份矩阵程序

给定一个方阵M[r][c],其中r是一定数量的行,c是列,使得r=c,我们必须检查M是否是单位矩阵。/p

恒等矩阵也称为大小为nxn方阵的单位矩阵,其中对角元素的整数值为1,非对角元素的整数值为0

就像下面给定的示例-

$$I1=\begin{bmatrix}1\end{bmatrix},\I2=\begin{bmatrix}10\01\end{bmatrix},\I3=\begin{bmatrix}100\010\001\end{bmatrix},\In=\begin{bmatrix}

100...0\

010...0\

001...0\

。......\

。......\

000...1\

\end{bmatrix}$$

Input:m[3][3]={{1,0,0},

{0,1,0},

{0,0,1}}

Output:yes

Input:m[3][3]=={{3,0,1},

{6,2,0},

{7,5,3}}

Output:no

Start

Step1-declarefunctionforfindingidentitymatrix

intidentity(intnum)

declareintrow,col

LoopForrow=0andrownumandrow++

LoopForcol=0andcolnumandcol++

IF(row=col)

Print1

Else

Print0

Step2-InmAIn()

Declareintsize=4

Callidentity(size)

Stop

#includestdio.h

intidentity(intnum){

introw,col;

for(row=0;rownum;row++){

for(col=0;colnum;col++){

if(row==col)

printf(%d,1);

else

printf(%d,0);

printf(

}return0;}intmain(){intsize=4;identity(size);return0;}

1000

0100

0010

0001

以上就是C语言中的身份矩阵程序的详细内容。