teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

指摘されたことを修正した後の出力の質問です。よろしくお願いします。

2018/07/13 08:58

投稿

Teemro_431265
Teemro_431265

スコア29

title CHANGED
@@ -1,1 +1,1 @@
1
- 代入がうまくいきません
1
+ 代入がうまくいきません(訂正)
body CHANGED
@@ -1,25 +1,19 @@
1
- 最終的には5×5の行列を1を入力して上下に反転、0を入力して左右に反転するプログラムを作りたいです。自分としてはfor文使ってやればいいのかなと思っています。コンパイルをかけところエラーが出てきたのですがおそらく代入うま行ってなと思われます。ように書くのが適切か?
1
+ 最終的には5×5の行列を1を入力すると縦に反転、0を入力すると横に反転するプログラムを作りたいです。自分としてはfor文使ってやればいいのかなと思っています。コンパイルは通ったのですが出力意図したものと全います。最後「不適切な数値が入力されました」は正しく動きま
2
2
 
3
-  エラー内容
3
+ エラー内容
4
- 09b1.c:22:9: error: use of undeclared identifier 'mat2'
5
- mat2[i][j]=mat[i][j];
4
+ 反転する方向を指定してください(縦:0、横:1)1
6
- ^
5
+ 0
7
- 09b1.c:23:21: error: use of undeclared identifier 'mat2'
8
- printf("%d",mat2[i][j]);
9
- ^
6
+ 0
10
- 09b1.c:31:9: error: use of undeclared identifier 'mat3'
11
- mat3[i][j]=mat[i][j];
12
- ^
7
+ 0
13
- 09b1.c:32:21: error: use of undeclared identifier 'mat3'
8
+ 1
9
+ 0
14
10
 
15
-
16
11
  ```c
17
-
18
12
  #include<stdio.h>
19
13
  #define r 5
20
14
  #define c 5
21
15
  int main(){
22
- int mat[r][c];
16
+ int mat[r][c],mat2[r][c],mat3[r][c];
23
17
  int i,j,assig;
24
18
  //要素
25
19
  int mat1[r][c]={{1,1,1,1,1},{0,1,1,1,1},{0,0,1,1,1},{0,0,0,1,1},{0,0,0,0,1}};
@@ -29,32 +23,33 @@
29
23
  for(j=0;j<c;j++){
30
24
  mat[i][j]=mat1[i][j];
31
25
  }
26
+ //printf("%d",mat[i][j]);
32
27
  }
33
28
  printf("反転する方向を指定してください(縦:0、横:1)");
34
29
  scanf("%d",&assig);
35
30
  if(assig==0){
36
- //上下に反転
31
+ //に反転
37
32
  for(i=4;i>=0;i--){
38
33
  for(j=4;j>=0;j--){
39
34
  mat2[i][j]=mat[i][j];
40
- printf("%d",mat2[i][j]);
41
35
  }
36
+ printf("%d\n",mat2[i][j]);
37
+
42
38
  }
43
39
  }
44
40
  else if(assig==1){
45
- //左右に反転
41
+ //に反転
46
42
  for(j=4;j>=0;j--){
47
43
  for(i=4;i>=0;i--){
48
44
  mat3[i][j]=mat[i][j];
49
- printf("%d",mat3[i][j]);
50
45
  }
46
+ printf("%d\n",mat3[i][j]);
51
47
  }
52
48
  }
53
49
  else{
54
- printf("不適切な数値が入力されました");
50
+ printf("不適切な数値が入力されました\n");
55
51
  }
56
52
 
57
53
  return 0;
58
54
  }
59
-
60
55
  ```