06年计算机等级考试二级C程序修改与设计2 |
|
www.nanhushi.com 佚名 不详 |
给定程序modi1.c中函数 fun 的功能是:将未在字符串s中出 现而在字符串t中出现的字符形成一个新的字符串放在u中,u中字 符按原字符串中字符顺序排列,不去掉重复字符。 例如,当s = "abcde",t = "bdfgg"时, u中的字符串为"fgg"。 请改正函数fun中的错误,使它能得出正确的结果。注意:不 要改动main函数,不得增行或删行,也不得更改程序的结构! 程序 : #include #include #include void fun (char *s, char *t, char *u) { int i, j, sl, tl; sl = strlen(s); tl = strlen(t); /************found************/ for (i=0; i/************found************/ { for (j=0; j if (t[i] == s[j]) break; if (j=sl) *u++ = t[i]; } /************found************/ u = ’\0’; } main() { char s[100], t[100], u[100]; clrscr(); printf("\nplease enter string s:"); scanf("%s", s); printf("\nplease enter string t:"); scanf("%s", t); fun(s, t, u); printf("the result is: %s\n", u); }
|
|
|
文章录入:杜斌 责任编辑:杜斌 |
|
上一篇文章: 06年计算机等级考试二级C程序修改与设计 下一篇文章: 二级考试C语言的联合类型讲解 |
【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
|