Solved

# Having problem with Array  practice excises

Posted on 1998-12-13
Medium Priority
164 Views
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.

0
Question by:muhbest
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 8

Expert Comment

ID: 1180097
We don't do your homework for you.  It's against EE policy.

Have a go, and post your code asking specific questions if you run into problems
0

LVL 4

Expert Comment

ID: 1180098
I agree with Answer2000 - give it a try yourself and then send in your queries regarding any problems.

0

LVL 1

Expert Comment

ID: 1180099
It is not that difficult.  :)  think ||. that is all I am saying.
0

LVL 10

Accepted Solution

RONSLOW earned 200 total points
ID: 1180100
cannot be done as you cannot has a function with prototype

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

the [][] doesn't work (only the last [...] can be empty

0

## Featured Post

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
###### Suggested Courses
Course of the Month15 days, 2 hours left to enroll