質問編集履歴
1
コードの全文を提示しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,9 +56,85 @@
|
|
56
56
|
|
57
57
|
|
58
58
|
|
59
|
-
```
|
59
|
+
```c
|
60
60
|
|
61
|
+
#include <stdio.h>
|
62
|
+
|
63
|
+
#include <stdlib.h>
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
void PrintMatrix(double **A, int n){
|
68
|
+
|
69
|
+
int i, j;
|
70
|
+
|
71
|
+
double *ai;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
ai = *A;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
for( i = 0 ; i < n ; i++){
|
80
|
+
|
81
|
+
for( j = 0 ; j < n ; j++){
|
82
|
+
|
83
|
+
printf("%6.1f", *(ai+j));
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
ai+=n;
|
88
|
+
|
89
|
+
printf("\n");
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
int main(void){
|
98
|
+
|
99
|
+
int i = 0, j = 0, N;
|
100
|
+
|
101
|
+
double **A;
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
//次元Nをキーボードから入力
|
106
|
+
|
107
|
+
printf("N=");
|
108
|
+
|
109
|
+
scanf("%d", &N);
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
//行列A用のメモリを確保
|
114
|
+
|
115
|
+
A = malloc(N*sizeof(double *));
|
116
|
+
|
117
|
+
for(i=0;i<N;i++){
|
118
|
+
|
119
|
+
A[i] = malloc(N*sizeof(double));
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
if(A==NULL){
|
124
|
+
|
125
|
+
printf("Cannot allocate memory.\n");
|
126
|
+
|
127
|
+
exit(1);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
//行列Aの要素
|
136
|
+
|
61
|
-
for( i = 0 ; i < N ; i++ ){
|
137
|
+
for( i = 0 ; i < N ; i++ ){
|
62
138
|
|
63
139
|
for( j = 0 ; j < N ; j++ ){
|
64
140
|
|
@@ -67,6 +143,26 @@
|
|
67
143
|
}
|
68
144
|
|
69
145
|
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
//行列Aを表示
|
150
|
+
|
151
|
+
printf("A = \n");
|
152
|
+
|
153
|
+
PrintMatrix(A,N);
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
//行列Aメモリを開放
|
160
|
+
|
161
|
+
free(A);
|
162
|
+
|
163
|
+
return 0;
|
164
|
+
|
165
|
+
}
|
70
166
|
|
71
167
|
```
|
72
168
|
|