-
Notifications
You must be signed in to change notification settings - Fork 3
/
printMat.c
72 lines (62 loc) · 1.65 KB
/
printMat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <string.h>
#include <stdio.h>
#include "printMat.h"
#include "matMult.h"
void printVec(const double *A, const int n, const char *nm) {
int i, nc, ns= 255-20;
char s[256], *ps;
ps= &s[0];
nc= sprintf(ps, "%s= [%g", nm, A[0]);
ns-= nc;
ps+= nc;
for(i= 1; i<n && ns>0; i++) {
nc= sprintf(ps, ", %g", A[i]);
ns-= nc;
ps+= nc;
}
if(ns>0) sprintf(ps, "]");
PRNT("%s\n",s);
}
void printTri(const double *A, const int n, const char *nm) {
int c, r, i, sl= strlen(nm);
PRNT("%s= [", nm);
for(r= 0; r<n; r++) {
for(c= 0; c<n; c++) {
if(r>c) {
i= (r*(r+1))/2 + c;
} else {
i= (c*(c+1))/2 + r;
}
PRNT("%g", A[i]);
if(c<(n-1)) {
PRNT(", ");
} else {
if(r<(n-1)) {
PRNT("\n ");
for(i= 0; i<sl; i++) PRNT(" ");
} else {
PRNT("]\n");
}
}
}
}
}
void printMat(const double *A, const int n, const int m, const char *nm) {
int c, r, i, sl= strlen(nm);;
PRNT("%s= [", nm);
for(r= 0; r<n; r++) {
for(c= 0; c<m; c++) {
PRNT("%g", A[r + n*c]);
if(c<(m-1)) {
PRNT(", ");
} else {
if(r<(n-1)) {
PRNT("\n ");
for(i= 0; i<sl; i++) PRNT(" ");
} else {
PRNT("]\n");
}
}
}
}
}