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
3 Respostas
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 ...
0
Leif Thank you my friend😊
0
You're welcome.