#include <stdio.h>
#include <math.h>

double dot_product (double *a, double *b, size_t n) {
  double acc=0;
  for (size_t i=0; i < n; ++i)
    acc += a[i]*b[i];
  return acc;
}

int is_ortho (double *m, size_t n) {
  for (size_t i=0; i < n; ++i) {
    for (size_t j=i; j < n; ++j) {
       double p=dot_product (m+i*n, m+j*n, n);
       if (i==j) { if (fabs(p-1) > 1e-6) return 0; }
       else      { if (       p  > 1e-6) return 0; }
    }
  }
  return 1;
}

int main(void) {
	double m1[] = { 0.96, -0.28, 0.28, 0.96 };
	double m2[] = { 1, 0, 0, -1 };
	double m3[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	double m4[] = { 1 };
	printf ("%d", is_ortho(m1, 2));
	printf ("%d", is_ortho(m2, 2));
	printf ("%d", is_ortho(m3, 3));
	printf ("%d", is_ortho(m4, 1));
	return 0;
}
