Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Solved

Posted on 1998-12-13

Write a function 'identity' which returns a 1 if the array argument passed to it represents an identity matrix, and returns 0 otherwise.

An identity matrix is an m by m array of integers, where the values of the elements on the principle diagonal (row subscript == col subscript)equal 1, and all other elements are 0.

for example:

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

is an identity matrix of order 4 by 4,

1 0 0

0 1 0

0 0 1

is an identity matrix of order 3 by 3,

and

1 1 5

0 1 0

0 0 1

is NOT an identity matrix.

The function identity is passed two arguments: the array, and the order of the matrix (ie the size of the two dimensions). Thus the prototype of the function would be written as:

int identity (int a[][], int m);

where a is the array and m represents the number of rows and columns.

You may assume that the number of rows always equals the number of

columns

for the array.

An identity matrix is an m by m array of integers, where the values of the elements on the principle diagonal (row subscript == col subscript)equal 1, and all other elements are 0.

for example:

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

is an identity matrix of order 4 by 4,

1 0 0

0 1 0

0 0 1

is an identity matrix of order 3 by 3,

and

1 1 5

0 1 0

0 0 1

is NOT an identity matrix.

The function identity is passed two arguments: the array, and the order of the matrix (ie the size of the two dimensions). Thus the prototype of the function would be written as:

int identity (int a[][], int m);

where a is the array and m represents the number of rows and columns.

You may assume that the number of rows always equals the number of

columns

for the array.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Title | # Comments | Views | Activity |
---|---|---|---|

maze travler | 6 | 55 | |

Which IDE to use to begin C++ training? | 5 | 63 | |

typedef std::deque<BYTE> ByteVector is broken in vs2012 | 23 | 86 | |

How to read a c++ line with strings and variable numbers of elements | 6 | 22 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**10** Experts available now in Live!