C语言中的身份矩阵程序

c语言中的身份矩阵程序

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

恒等矩阵

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

就像下面给定的示例 –

$$I1=begin{bmatrix}1 end{bmatrix},I2=begin{bmatrix}1 & 0 & 1 end{bmatrix},I3=begin{bmatrix}1 &0 & 0 &1 & 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: yesInput: m[3][3] == { {3, 0, 1},   {6, 2, 0},   {7, 5, 3} }Output: no

算法

StartStep 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  In main()   Declare int size = 4   Call identity(size)Stop

示例

<!—

现场演示

–>

#includeint 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("

"); } return 0;}int main(){ int size = 4; identity(size); return 0;}

输出

1 0 0 00 1 0 00 0 1 00 0 0 1

以上就是C语言中的身份矩阵程序的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444077.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年12月17日 20:58:54
下一篇 2025年12月17日 20:59:09

相关推荐

发表回复

登录后才能评论
关注微信