2011 年(春季)江苏省计算机二级考试 C 语言上机部分试卷 上机试卷(01) 一、改错题(16 分) 【程序功能】 对存储在 string 数组内的英文句子中所有以 a 开始并以 e 结尾的单词做加密处理
加密规则:若单词长度为偶数个字符,则将组成该单词的所有字母循环左移一次;否则循环右移一次
例如,单词 able 经循环左移一次后变为 blea;单词 abide 经循环右移一次后变为 eabid
【测试数据与运行结果】 测试数据:she is able to abide her
屏幕输出:she is blea to eabid her
【含有错误的源程序】 #include #include void wordchange(char str[]) { int i,j,k,m; char c; for(i=0;str[i];i++) {for(j=i,k=i;isalpha(str[k]);k++); if(str[j]=='a' || str[k-1]=='e') {if((k-j)%2=0) {c=str[j]; for(m=k-1;m>j;m--) str[m]=str[m+1]; str[k-1]=c; } else {c=str[k-1]; for(m=k-1;m>j;m--) str[m]=sty[m-1]; str[j]=c; } } i=k; }
} void main() { char string[80]="she is able to abide her
"; wordchange(string[80]); puts(string); } 【要求】 1
将上述程序录入到文件myf1
c 中,根据题目要求及程序中语句之间的逻辑关系对程 序中的错误进行修改
改错时,可以修改语句中的一部分内容,调