编程题:C语言错误匹配
刘老师最近在教大一学生c语言,最近总有学生来请教他编程时遇到的报错问题。因为刘老师平时比较忙,他把这个任务交给了小陈同学,现在小陈把这些问题整理出来,来帮助他们更好掌握c语言。
小陈把常见的编译报错的Error问题都整理出来了,还罗列了一些表达式。给出Error信息和表达式,希望大家可以根据自己所掌握的c语言知识,来判断该问题是否是由该表达式引起的。这些Error信息,表达式都有对应的唯一编号,且一个Error问题都有唯一的对应的表达式引起。Error信息如下:
1. Error : Incorrect use of parentheses
2. Error : expected ',' or ';' before '}' token
3. Error : Invalid number in octal constant in the number
4. Error : the exponent part of the number does not specify a number
5. Error : Chinese characters appear in this line
6. Error : invalid operands of types 'int' and 'float' to binary 'operator%'
7. Error : the procedure did not end within the specified time
8. Error : the else does not detect a matching if
9. Error : too many initializers,array bounds overflow
10. Error : invalid operands of types 'int*' and 'int*' to binary 'operator+'
11. Error : undeclared identifier,expected constant expression,cannot allocate an array of constant size 0
12. Error : invalid conversion from 'const char*' to 'int' [-fpermissive]
表达式如下:
1. int a=0xhh;
2. float a=123.456E;
3. int x=081;
4. int x=071,y=70; if(x>y)( printf("x比y大"); ) else( printf("y比x大"); )
5. char x; scanf("%c",&x); switch(x){ case "a" : printf("你输入的是a"); break; }
6. int a[n],n=10;
7. int *pa=10,*pb=20,*a; a = pa + pb;
8. char a[4]={'a','b','c','d','e'};
9. int x=100000000; while((x++)<2147483648)
10. int t=1; if(t>0) if(t>10) printf("aaa"); else printf("bbb") else printf("ccc");
11. int x=2022; float y=8; printf("%d",x%y);
12. double x; scanf("%2.3lf",&x); printf("%lf",x);
13. int a=10;
14. int x; scanf("%d",&x); printf("%d",&x);
15. int x=10,y=20; x=x>y?x:y;
16. int a=0
注:Error与表达式信息所使用的字符是“英文半角”格式
### 输入格式:
本题一共两个输入:
第一个为Error信息的编号
第二个为表达式编号
### 输出格式:
第一行打印Error信息对应的编号及内容和表达式对应的编号及内容
第二行打印出该问题是否和该表达式是否相匹配,匹配输出 ‘ **MATCH** ’ , 反之输出 ' **NOT MATCH** '
### 输入样例:
在这里给出一组输入。例如:
in
2 16
in
2 15
### 输出样例:
在这里给出相应的输出。例如:
out
you choose the ERROR INFORMATION TWO{Error : expected ',' or ';' before '}' token } and the EXPRESS OPTION SIXTEEN{int a=0}
MATCH
out
you choose the ERROR INFORMATION TWO{Error : expected ',' or ';' before '}' token } and the EXPRESS OPTION FIFTEEN{int x=10,y=20; x=x>y?x:y;}
NOT MATCH
答案:若无答案欢迎评论
出题人 2001班陈辉
预计使用40-50分钟
小陈把常见的编译报错的Error问题都整理出来了,还罗列了一些表达式。给出Error信息和表达式,希望大家可以根据自己所掌握的c语言知识,来判断该问题是否是由该表达式引起的。这些Error信息,表达式都有对应的唯一编号,且一个Error问题都有唯一的对应的表达式引起。Error信息如下:
1. Error : Incorrect use of parentheses
2. Error : expected ',' or ';' before '}' token
3. Error : Invalid number in octal constant in the number
4. Error : the exponent part of the number does not specify a number
5. Error : Chinese characters appear in this line
6. Error : invalid operands of types 'int' and 'float' to binary 'operator%'
7. Error : the procedure did not end within the specified time
8. Error : the else does not detect a matching if
9. Error : too many initializers,array bounds overflow
10. Error : invalid operands of types 'int*' and 'int*' to binary 'operator+'
11. Error : undeclared identifier,expected constant expression,cannot allocate an array of constant size 0
12. Error : invalid conversion from 'const char*' to 'int' [-fpermissive]
表达式如下:
1. int a=0xhh;
2. float a=123.456E;
3. int x=081;
4. int x=071,y=70; if(x>y)( printf("x比y大"); ) else( printf("y比x大"); )
5. char x; scanf("%c",&x); switch(x){ case "a" : printf("你输入的是a"); break; }
6. int a[n],n=10;
7. int *pa=10,*pb=20,*a; a = pa + pb;
8. char a[4]={'a','b','c','d','e'};
9. int x=100000000; while((x++)<2147483648)
10. int t=1; if(t>0) if(t>10) printf("aaa"); else printf("bbb") else printf("ccc");
11. int x=2022; float y=8; printf("%d",x%y);
12. double x; scanf("%2.3lf",&x); printf("%lf",x);
13. int a=10;
14. int x; scanf("%d",&x); printf("%d",&x);
15. int x=10,y=20; x=x>y?x:y;
16. int a=0
注:Error与表达式信息所使用的字符是“英文半角”格式
### 输入格式:
本题一共两个输入:
第一个为Error信息的编号
第二个为表达式编号
### 输出格式:
第一行打印Error信息对应的编号及内容和表达式对应的编号及内容
第二行打印出该问题是否和该表达式是否相匹配,匹配输出 ‘ **MATCH** ’ , 反之输出 ' **NOT MATCH** '
### 输入样例:
在这里给出一组输入。例如:
in
2 16
in
2 15
### 输出样例:
在这里给出相应的输出。例如:
out
you choose the ERROR INFORMATION TWO{Error : expected ',' or ';' before '}' token } and the EXPRESS OPTION SIXTEEN{int a=0}
MATCH
out
you choose the ERROR INFORMATION TWO{Error : expected ',' or ';' before '}' token } and the EXPRESS OPTION FIFTEEN{int x=10,y=20; x=x>y?x:y;}
NOT MATCH
答案:若无答案欢迎评论
出题人 2001班陈辉
预计使用40-50分钟