二级C语言上机100题
1、 改错
下列给定程序中,函数fun的功能是:依次取出字符串中所有数字字符,形成新的字符串,并取代原字符串。
请改正程序中的错误,使程序能得出正确的结果。
注意,不要改多main函数,不得增行或删行,也不得更改程序的结构!
试题程序
#include #include void fun (char *s) { int i,j;
for (i=0,j=0;s[i]!='\0';i++)
**************************************** if (s[i]>='0' && s[i]<='9')
s[j]=s[i]; ——————j改为j++ *************************************** s[j]="\0"; ——————s[j]='\0' }
main()
{char item[80]; clrscr();
printf("\nEnter a string:");gets(item); printf("\n\nThe string is :\%s\n",item); fun (item);
printf("\n\nThe string of changing is :\%s\n",item); }
2、 改错
下列给定程序中,函数fun的功能是:分别统计字符串中大写字母和小写字母的个数。例如,给字符串s输入:AAaaBBb123CCccccd,则应该输出结果:upper=6,lower=8。 请改正程序中的错误,使程序能得出正确的结果。
注意,不要改多main函数,不得增行或删行,也不得更改程序的结构! 试题程序
#include #include
**********************************
void fun (char *s,int a, int b) ————a应为*a,b应为*b { while(*s)
{ if (*s>='A' && *s<='Z')
***********************************