题目
请补充函数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);
}
第1题
请补充fun()函数,该函数的功能是:把字符的ASCII码中为奇数的字符从字符串str中删除,结果仍然保存在字符串str中,字符串str从键盘输人,其长度作为参数传人fun()函数。
例如,输入“abcdef”,则输出“bdf”。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在mare()函数的横线上填入所编写的若干表达式或语句。
试题程序:
第2题
请补充函数fun(char *s),该函数的功能是把字符串中的内容逆置。
例如:字符串中原有的字符串为abcde,则调用该函数后,串中的内容变为edcba。
注意;部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
$include<string.h>
include<conio.h>
include<stdio.h>
define N 81
void fun(char*s)
{
int i=0,t,n=strlen(s);
for(;【 】;i++)
{
t=*(s+i);
【 】;
【 】;
}
}
main()
{
char a[N];
clrscr();
printf("Enter a string:");
gets(a);
printf("The original string is:");
puts(a);
fun(a);
printf("\n");
printf("The string after modified:");
puts(a);
}
第3题
请补充函数fun(),该函数的功能是:把字符下标能铍2或3整除的字符从字符串str中删除,把剩余的字符重新保存在字符串str中。字符串str从键盘输入,其长度作为参数传入函数fun()。
例如,输入“abcdefghijk”,输出“bfh”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
void fun(char s[], int n)
{
int i, k;
【 】;
for(i=0; i<n; i++)
{
s[k++]=s[i];
if(【 】)
k--;
}
【 】;
}
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);
}
第4题
请补充函数fun(),该函数的功能求能整除x且是偶数的数,把这些数保存在数组bb中,并按从大到小的顺序输出。
例如当x=20时,依次输出:20 10 4 2。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<conio.h>
include<stdio.h>
void fun(int k,int bb[ ])
{
int i;
int j=0;
for(【l】;i<=k;i++)
{
if(【 】)
bb[i++]=i;
}
printf("\n\n");
for(i=【 】;i>=0;i--)
printf(“%d”,bb[i]);
}
main()
{
int k=1;
int bb[100];
clrscr();
printf(“\nPlease input X=”);
scanf(“%d”,&k);
fun(k,bb);
}
第5题
请补充函数fun(),该函数的功能是:把ASCII码为奇数的字符从字符串str中删除,结果仍然保存在字符串str中。字符串str从键盘输入,其长度作为参数传入函数fun()。
例如,输入“abcdef”,输出“bdf”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
void fun(char s[],int n)
{
int i, j;
j=0;
for(i=0;【 】;i++)
{
if(【 】)
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);
}
第6题
请补充函数fun(),该函数的功能是:把从主函数中输入的字符串str2接在字符串str1的后面。
例如:str1=“How do”,str2=“you do?”,结果输出: How do you do?
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
define N 40
void fun(char*str1,char *str2)
{
int i=0;
char *pl=str1;
char*p2=str2;
while(【 】)
i++;
for(;【 】;i++)
*(p1+i)=【 】;
*(p1+i)='\0';
}
main()
{
char str1[N],str2[N);
clrscr();
printf("*****Input the string str1 & Str2*****\n");
printf("\nstr1:");
gets(str1);
printf("\nstr2:");
gets(str2);
printf("**The string str1 & str2**\n");
puts(str1);
puts(str2);
fun(str1,str2);
printf("*****The new string *****\n");
puts(str1);
}
第7题
请补充函数fun(),该函数的功能是:把字符下标为非素数的字符从字符串sb中删除,把字符下标为素数的字符重新保存在字符串e口中。字符串sb从键盘输入,其长度作为参数传入函数fun()。
例如,输入“abcdefghijkl”,输出“cdfhl”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
void fun(char s[],int n)
{
int i, j, k, flag;
【 】;
for(i=0; i<n; i++)
{
if (i>1)
s [k++] =s [i];
flag=I;
for(【 】; j<i&&flag; j++)
if (i%j==0)
{
flag=0;
【 】
}
}
s [k]='\0';
}
main()
{
int i=0, strlen=0;
char str[N];
clrscr ();
printf("\n Input a string:\n");
gets (str);
while (str [i] !='\0')
{
strlen++;
i++;
}
fun (str, strlen);
printf("\n*** display string ***\n");
puts (str);
}
第8题
请补充函数fun(),该函数的功能是把数组aa中的奇数元素按原来的先后顺序放在原数组后面。
例如,输入“33,67,42,58,25,76,85,16,41,56”,输出结果“42,58,76,16,56,33,67,25,25,41。
注意:部分源程序给出如下。
请勿改动主函数main和具他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 10
void fun(int aa[])
{
int i, j=0,k 0;
int bb IN];
for (i 0; i<N; i++)
{
if (【 】)
bb[k++] aa[i];
else
aa [j++] =aa Ii];
for(i=0; i<k;【 】)
aa[j] bb[i];
}
main ()
{
int i;
int aa[N]={33, 67, 42,58,25, 76, 85, 16,
41,56};
clrscr ();
printf("\n*** original list ***\n");
for (i=0; i<N; i++)
printf("%4d", aa[i]);
fun (aa);
printf("\n*** new list ***\n");
for (i=0; i<N; i++)
printf("%4d", aa[i]);
}
第9题
请补充函数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);
}
第10题
请补充函数fun(),该函数的功能是把数组aa中的偶数元素按原来的先后顺序放在原数组后面。
例如,输入“33,67,42,58,25,76,85,16,41,56”,输出结果“33,67,25,85,41,42,58,76,16,56”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
define N 10
void fun (int aa [] )
{
int i, j=0,k=0;
int bb [N];
for (i=0;i<N; i++)
{
if (【 】)
bb [k++] =aa [i];
else
aa [ j ++ ] =aa [i];
}
for(i=0;【 】;i++,j++)
aa[j] =bb [i];
}
main ()
{
int i;
int aa[N]={33, 67,42,58,25, 76, 85, 16,
41,56};
clrscr ();
printf("\n*** original list ***\n");
for (i=0;i<N; i++)
printf ("%4d", aa [i] );
fun (aa);
printf("\n*** new list ***\n ");
for (i=0; i<N; i++)
printf ("%4d", aa [i] );
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!