A.工伤保险的政策、法律、法规
B.安全生产管理知识和方法
C.国家有关安全生产的方针、政策等
D.典型事故案例分析
第6题
请补充函数fun(),该函数的功能是:把字符串str中的字符按字符的ASCⅡ码降序排列,处理后的字符串仍然保存在原串中,字符串及其长度作为函数参数传入。
例如,如果输入“cdefgh”,则输出为“hgfedc”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
void fun (char s [], int n)
{
int i, j;
char ch;
for (i=0; i<n; i++)
for(j=【 】;j<n;j++)
if (s[i]<s [j])
{
ch=s [j];
【 】;
s [i] =ch;
}
main ()
{
int i=0, strlen=0;
char str [N];
clrscr ();
printf ("\nInput a string: \n");
gets (str);
while (str [i] !=' \0')
{
strlen++;
i++;
}
fun (str, strlen);
printf ("\n***display string ***\n");
puts (str);
}
第7题
请补充fun()函数,该函数的功能是:把字符的ASCII码中为奇数的字符从字符串str中删除,结果仍然保存在字符串str中,字符串str从键盘输人,其长度作为参数传人fun()函数。
例如,输入“abcdef”,则输出“bdf”。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在mare()函数的横线上填入所编写的若干表达式或语句。
试题程序:
第8题
从键盘输入一组小写字母,保存在字符数组str中。请补充函数proc(),该函数的功能是:把字符数组str中字符下标为奇数的小写字母转换成对应的大写字母,结果仍保存在原数组中。例如,输入abcdefg,输出aBcDeFg。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proe()的横线上填入所编写的若干表达式或语句。
试题程序:
第9题
请补充函数fun(),该函数的功能是:把ASCⅡ码为偶数的字符从字符串s打中删除,结果仍然保存在字符串srt中,字符串str从键盘输入,其长度作为参数传入函数fun()。
例如,输入“abcdef”,输出“ace”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
inc lude< stdio, h>
define N 80
【 】
{
int i, j;
【 】
for (i=0;i<n;i++)
{
if (s [i] %2!=0)
s [j++]=s [i];
}
【 】;
}
main ()
{
int i=0, strlen=0;
char str[N];
clrscr ();
printf ("\nInput a string:\n");
gets (str);
while (str [i] !=' \0' )
{
strlen++;
i++;
}
fun (str, strlen);
printf("\n*** display string ***\n");
puts (str);
}
第10题
第11题
下列给定程序中,函数proc的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码升序排序后输出。 例如,输入opdye,则应输出deopy。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<string.h> include<stdlib.h> include<conio.h> include<stdio.h> //****found**** int proc(char str[]) { char c; unsigned i,j; for(i=0;i<strlen(str)-1;i++) for(j=i+1;j<strlen(str);j++) if(str[i]>str[j]) { c=str[j]: //****found**** str[j]=str[i++]; str[i]=c; } } void main { char str[81]; system("CLS"); printf("\nPlease enter a character string:"); gets(str); printf("\n\nBefore sorting:\n%s",str); proc(str); printf("\nAfter sorting decendingly:\n %s",str); }
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!