0

C code

https://code.sololearn.com/ctIhIFEQJD4B/#c Hello friends see the above code.. I need to print whether it is a toeplitz matrix or not.. I got the logic somewhat but I don"t know how to get the exact answer.. https://en.wikipedia.org/wiki/Toeplitz_matrix Go through the above link of toeplitz matrix

3rd Nov 2018, 9:09 AM
Dhiviya Thirumavalavan
Dhiviya Thirumavalavan - avatar
3 Respuestas
0
Looks good! You are overstepping the bounds of the arrays since you compare against a[i+1][j+1], so i and j need to stop one short! For the test I would suggest to introduce a variable "is_toeplitz" replacing the "equal" that you have now. Set it to 1 before the test - this way you assume the matrix is toeplitz. Inside the loop set is_toeplitz to zero once "a[i][j]!=a[i+1][j+1]". That means, once the elements diagonal are not equal, you know it is not toeplitz; so you set the is_toeplitz flag to "false" (=0, in C). In the end you can test if is_toeplitz is non-zero: if(is_toeplitz) { printf("Toeplitz); } else ...
3rd Nov 2018, 2:58 PM
Leif
Leif - avatar
0
Leif Thank you my friend😊
3rd Nov 2018, 3:16 PM
Dhiviya Thirumavalavan
Dhiviya Thirumavalavan - avatar
0
You're welcome.
3rd Nov 2018, 3:20 PM
Leif
Leif - avatar