Chinaunix首页 | 论坛 | 博客
  • 博客访问: 383950
  • 博文数量: 55
  • 博客积分: 1907
  • 博客等级: 上尉
  • 技术积分: 869
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-04 19:30
文章分类

全部博文(55)

文章存档

2011年(32)

2010年(23)

分类: C/C++

2010-12-04 11:47:29

/*
 * 单位矩阵(identity matrix)就是一个正方形矩阵,它除了主对角线的元素值为1
 * 以后,其余元素的值均为 0。例如:
 * 1 0 0
 * 0 1 0
 * 0 0 1
 * 就是一个3*3的矩阵。编写一个名为 identity_matrix 的函数,它接受一个
 * 10*10整型矩阵为参数,并返回一个布尔值,提升该矩阵是否为单位矩阵。
 */
 

/* This problem is simple because the argument must be a specific size.
 * The test for zero or one is simple, though perhaps not immediately obvious.
 */


/* Test a 10 by 10 matrix to see if it is an identity matrix */

#define FALSE    0
#define TRUE    1;

int    identity_matrix( int matrix[10][10] )
{
    int    row;
    int    column;

    /* Go through each of the matrix elements */

    for( row=0; row<10; row++ )
    {
        for( column=0; column<10; column++ )
        {
            /*
             * If the row number is equal to the column number,
             * the value should be 1, else 0.
             */

            if( matrix[row][column] != ( row == column ) )    // ??

                    return FALSE;
        }
    }

    return TRUE;
}

 

 

 

 


 

阅读(1221) | 评论(0) | 转发(0) |
0

上一篇:数组之8.1

下一篇:数组之8.4

给主人留下些什么吧!~~