题目
第4题
第5题
请补充函数fun(),该函数的功能是;删除字符数组中小于等于指定字符的字符,指定字符从键盘输入,结果仍保存
例如,输入“abcdefghij”,指定字符为‘d’,则结果输出“defghij”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio. h>
define N 80
void fun (char s[], char ch)
{
int i=0, j=0;
while (s [i] )
{
if (s Iii<ch)
【 】;
else
{
【 】
i++;
}
}
【 】
}
main ()
{
char str [N], ch;
clrscr ();
printf("\n Input a string:\n");
gets (str);
printf("\n*** original string ***\n");
puts (str);
printf("\n Input a character:\n");
scanf ("%c", &ch);
fun(str, ch);
printf("\n*** new string ***\n");
puts (str);
}
第6题
字符串str由数字字符‘0’和‘1’组成(长度不超过8个字符),可看作二进制数,请补充函数fun(),该函数的功能是:把str字符串转换成十进制数,结果由函数返回。例如,输入“1001”,结果输出:9。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<stdlib.h>
include<string.h>
int fun(char *str)
{
int n;
char *p=str;
【 】;
p++;
while (*p)
{
n=【 】;
p++;
}
return【 】;
}
main()
{
char str[9];
int i;
int n;
printf ("Enter a string made up of '0' and
'1' digital character:");
gets (str);
if (strlen(str)>8)
{
printf ("Error:string too longer!
please input again !\n\n");
exit(0);
}
for(i=0;str[i];i++)
if(str[i]<'0'||str[i]>'1')
{
printf("Error:%c not is '0'and
'1' digital character !\n\n",
str[i]);
exit(0);
}
printf("The original string:");
puts(str);
n=fun(str);
printf("\n%s is convered to decimal
number:%d\n\n",str,n);
}
第7题
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!