
给定一个方阵 M[r][c],其中“r”是一定数量的行,“c”是列,使得 r = c,我们必须检查“M”是否是单位矩阵。
恒等矩阵也称为大小为nxn方阵的单位矩阵,其中对角元素的整数值为1,非对角元素的整数值为0 p>
就像下面给定的示例 -
$$I1=\begin{bmatrix}1 \end{bmatrix},\ I2=\begin{bmatrix}1 & 0 \0 & 1 \end{bmatrix},\ I3=\begin{bmatrix}1 &0 & 0 \0 &1 & 0 \0 &0 &1 \end{bmatrix},\In=\begin{bmatrix}
1 &0 &0 &...&0 \
0 &1 &0 &...&0\
0 &0 &1 &...&0\
立即学习“C语言免费学习笔记(深入)”;
。 &. &. &...&.\
。 &. &. &...&.\
0 &0 &0 &...&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: noStart
Step 1 -> declare function for finding identity matrix
int identity(int num)
declare int row, col
Loop For row = 0 and row < num and row++
Loop For col = 0 and col < num and col++
IF (row = col)
Print 1
Else
Print 0
End
End
Step 2 -> In main()
Declare int size = 4
Call identity(size)
Stop#include<stdio.h>
int identity(int num){
int row, col;
for (row = 0; row < num; row++){
for (col = 0; col < num; col++){
if (row == col)
printf("%d ", 1);
else
printf("%d ", 0);
}
printf("</p><p>");
}
return 0;
}
int main(){
int size = 4;
identity(size);
return 0;
}1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
以上就是C语言中的身份矩阵程序的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号