I am generating a mxm
matrix where m
value is the square of n
value i.e) m=n*n
, for example if n=3
the value of m
will be 9
and a 9x9
matrix will be generated.
1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0 0
I need to print a space after every n
times the row and column elements printed, for example if n=3
a space should be printed after every 3
elements of rows and 3
elements of column are printed.
1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0 0
Is there anyway to print a matrix like this?. Iam using c++.
Aucun commentaire:
Enregistrer un commentaire