概论3

一、常见编程错误

1 语法错误

2运行时错误

#include <stdio.h>

int main()

{

int year;

char first,second,third;

/*

scanf("%d",&year);

scanf("%c%c%c",&first,&second,&third);

printf("%d",year);

printf("%c%c%c\n",first,second,third);

输入

100 CR

ABC

输出

100

AB

*/

scanf("%d",&year);

scanf(" %c%c%c",&first,&second,&third);

printf("%d",year);

printf("%c%c%c\n",first,second,third);

/*

输入

100 CR

ABC

输出

100ABC

*/

return 0;

}

错误解析:scanf在扫描数值时,首先会跳过输入中的任何空白和回车;而在扫描字符时,不跳过任何东西,除非%c占位符前面有空白。

3逻辑错误

你可能感兴趣的:(编程,C++,c,C#)