ok, I did that but it is still printing an extra row. I figured out that each identity matrix is supposed to have N-1 "1s" printed. I can make it so that it keeps track of the number of ones printed and when it reaches N-1 number of "1s" it will terminate out of the loop. how would I make it break out off this loop though? I know the break command, but putting it only makes it break out of the currecnt "else if (ones == N-1) statement when I tried it.
this is the code I tried but it just prints the exact same thing as the original:
Code:
#include <stdio.h>
#define N 15
int main()
{ float a[N][N];
float *p;
int zeros=0, ones=0;
a[0][0]=1;
for (p = &a[0][1]; p <= &a[N-1][N-1]; p++) {
zeros++;
if ( zeros == N+1 ) {
*p = 1.0;
zeros = 0;
ones++;
if (ones == N-1)
break;
}
else {
*p = 0.0;
}
}
for (p = &a[0][0]; p <= &a[N-1][N-1]; p++) {
zeros++;
if (zeros == N) {
printf("\n");
zeros = 0;
}
else
printf ("%.0f ", *p);
}
return 0;
}