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

質問編集履歴

1

define A 10と変更しインデントを揃えました

2020/06/22 02:00

投稿

MCV
MCV

スコア6

title CHANGED
File without changes
body CHANGED
@@ -2,92 +2,90 @@
2
2
  コード
3
3
  #include <stdio.h>
4
4
  #include <string.h>
5
- #define aaa 5
5
+ #define A 10
6
6
  int main (void){
7
- double ring_buff[aaa];
7
+ double ring_buff[A];
8
- int head=0; /* データの先頭を表す変数 */
8
+ int head=0; /* データの先頭を表す変数 */
9
- int tail=0; /* データの最後を表す変数 */
9
+ int tail=0; /* データの最後を表す変数 */
10
- int counter=0;
10
+ int counter=0;
11
- int i=0,j;
11
+ int i=0,j;
12
- char s[5];
12
+ char s[5];
13
13
 
14
14
 
15
- while(1){
15
+ while(1){
16
- printf("操作を選択してください(enq/deq/end):");
16
+ printf("操作を選択してください(enq/deq/end):");
17
- scanf("%s",s);
17
+ scanf("%s",s);
18
- //enq
18
+ //enq
19
- if(strcmp(s,"enq")==0){
19
+ if(strcmp(s,"enq")==0){
20
- if(counter==aaa-1){
20
+ if(counter==A-1){
21
- printf("enqできません,deqするか\n");
21
+ printf("enqできません,deqするか\n");
22
- }
22
+ }
23
- else {
23
+ else {
24
- printf("追加する値を入力してください==>");
24
+ printf("追加する値を入力してください==>");
25
- if(tail==aaa){
25
+ if(tail==A){
26
- tail=0;
26
+ tail=0;
27
- }
27
+ }
28
- scanf("%lf",&ring_buff[tail]);
28
+ scanf("%lf",&ring_buff[tail]);
29
- printf("tail=%d\n",tail);
29
+ printf("tail=%d\n",tail);
30
- tail++;
30
+ tail++;
31
-
32
- counter++;
33
- }
34
31
 
35
- }//end enq
36
- //deq
37
- else if(strcmp(s,"deq")==0){
38
- if(counter!=0){
32
+ counter++;
33
+ }
39
34
 
40
- printf("%2.0fはキューから削除されました\n",ring_buff[head]);
41
- printf("head=%d\n",head );
42
- head++;
43
- if(head==aaa-1){
44
- head=0;
45
- }
35
+ }
36
+ //deq
37
+ else if(strcmp(s,"deq")==0){
38
+ if(counter!=0){
46
39
 
40
+ printf("%2.0fはキューから削除されました\n",ring_buff[head]);
41
+ printf("head=%d\n",head );
42
+ head++;
43
+ if(head==A-1){
44
+ head=0;
47
- }
45
+ }
48
- else{
49
- printf("deqできません.\nプログラムを終了します");
50
46
 
51
- break;
52
- }
47
+ }
48
+ else{
49
+ printf("deqできません.\nプログラムを終了します");
53
50
 
54
- counter--;
55
- }//end deq
56
- //end
57
- else if(strcmp(s,"end")==0){
58
- printf("プログラムを終了します\n");
59
- break;
51
+ break;
60
- }//end end
52
+ }
61
53
 
62
- //中身表示
54
+ counter--;
63
- if(head<tail){
64
- printf("aa\n");**ボールドテキスト**
65
- for(i=0;i<tail-head;i++){
66
- printf("->%2.0f",ring_buff[head+i]);
67
- }
55
+ }
56
+ //end
57
+ else if(strcmp(s,"end")==0){
68
- printf("\n");
58
+ printf("プログラムを終了します\n");
59
+ break;
69
- }//end if
60
+ }//end end
70
61
 
62
+ //中身表示
71
- else if(head>tail){
63
+ if(head<tail){
72
- printf("bb\n");
73
- for(i=head;i<aaa-1;i++){
64
+ for(i=0;i<tail-head;i++){
74
- printf("->cc%2.0f",ring_buff[i]);
65
+ printf("->%2.0f",ring_buff[head+i]);
75
- }
66
+ }
67
+ printf("\n");
68
+ }
76
69
 
70
+ else if(head>tail){
77
- for(i=0;i<tail;i++){
71
+ for(i=head;i<A-1;i++){
78
- printf("->dd%2.0f",ring_buff[i]);
72
+ printf("->%2.0f",ring_buff[i]);
79
- }
73
+ }
80
- printf("\n");
81
- }//end else if
82
74
 
83
- else if(counter==0){
75
+ for(i=0;i<tail;i++){
84
- printf("データは空です\n");
76
+ printf("->%2.0f",ring_buff[i]);
85
- }
77
+ }
86
- printf("counter=%d\n",counter );
78
+ printf("\n");
79
+ }
87
80
 
81
+ else if(counter==0){
82
+ printf("データは空です\n");
83
+ }
84
+ printf("counter=%d\n",counter );
88
85
 
89
- }//end while
90
86
 
87
+ }
88
+
91
89
  return 0;
92
90
  }
93
91
  ```
@@ -95,4 +93,5 @@
95
93
  実行でenqを9回(1,2,...,9)
96
94
  そのあとdeqを6回
97
95
  またenqを6回(10,11,..,15)
98
- 最後にdeqを6回したとき、理想は(13,14,15)と出るようにしたいのですが
96
+ 最後にdeqを6回したとき、理想は(13,14,15)と出るようにしたいのですが
97
+ 9をdeqした後もう一度deqをすると10がdeqされず11がdeqされます