题目
下列给定程序中fun()函数的功能是:将n个无序整数从小到大排序。
请改正程序中的错误,使它能得出正确的结果。
注意;不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
include <stdlib.h>
fun(int n, int *a)
{ int i,j,p,t;
for (j=0;j<n-1;j++)
{ P=j;
/***************found*******************/
for(i=j+l;i<n-1;i++)
if (a[p]>a[i])
/***************found*******************/
t=i;
if (p!=j)
{t=a[j];a[j]=a[p];a[p]=t;}
}
}
putarr(iht n,int *z)
{int i;
for (i=l;i<=n;i++,z++)
{ printf("%4d",*z);
if (!(i%10)) printf("\n");
} printf ("\n");
}
main ()
{int aa[20]={9,3,0,4,1,2,5,6,8,10,7},n=11;
clrscr();
printf("\n\nBefore sorting %d numbers:\n",n); putarr(n,aa);
fun(n,aa);
printf("\nAfter sorting %d numbers:\n",n);putarr(n,aa);
}
第1题
下列给定程序中,函数fun()的功能是:将str所指字符串中的字母转换为按字母序列的后续字母(Z转换A,z转换a),其他字符不变。
请修改函数fun()中的错误,得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
第2题
下列给定程序中,函数fun()的功能是:将P所指字符串中的所有字符复制到b中,要求在每复制3个字符之后插入1个空格。
例如,若给a输入字符串:“ABCDEFGHIJK”,调用函数后,字符数组b中的内容为:“ABC DEF GHI JK”。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
第3题
下列给定程序中,函数fun()的功能是;将s所指字符串中的字母转换为按字母序列的后续字母(但Z转化为A,z转化为 a),其他字符不变。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <ctype.h>
include <conio.h>
void fun(char *s)
/*************found**************/
{ while(*s!='@')
{ if(*s>='A' &*s<='z'||*s>='a'&&*s<='z')
{if(*s=='Z') *S='A';
else if(*S=='z') *s='a';
else *s+=1;
}
/*************found**************/
(*s)++;
}
}
main()
{ char s[80];
clrscr();
printf("\n Enter a string with length <80:\n\n");gets(s);
printf("\n The string:\n\n");puts(s);
fun(s);
printf("\n\n The Cords:\n\n");puts(s);
}
第4题
下列给定程序中,函数fun()的功能是:将字符串p中所有字符复制到字符串b中,要求每复制3个字符之后插入一个空格。例如,在调用fun()函数之前给字符串a输入ABCDEFGHIJK,调用函数之后,字符串b中的内容则为ABC DEF GHI JK。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio. h>
void fun (char *p, char *b)
{ int i, k=0;
while (*p)
/*************found***************/
{ i=l;
/*************found***************/
while (i<3|| *P)
{
b[k]=*p;
k++; p++; i++;
}
if (*p)
/*************found***************/
{ b[k]= ' ';}
}
b[k]= '\0';
}
main ()
{ char a[80],b[80];
printf ("Enter a string: "); gets (a);
printf ("The original string: ");
puts (a);
fun (a,b);
printf("\nThe string after insert
space: "); puts(b); printf("\n\n ");
}
第5题
给定程序MODll.C中函数fun的功能是:比较两个字符串,将长的那个字符串的首地址作为函数值返回。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
第6题
下列给定程序中函数fun()的功能是:将长整型数中每一位上为奇数的数依次取出,构成一个新数放在冲。高位仍在高位,低位仍在低位。例如当s中的数为87653142时,t中的数为7531。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conlo.h>
void fun (long s, long *t)
{int d;
long s1=1;
/*************found**************/
t=0;
while(s>0)
{ d=s%10;
/*************found**************/
if(d%2==0)
{*t=d*s1+*t;
s1*=10;
}
s/=10;
}
}
main()
{long s, t;
clrscr();
printf("\nPlease enter s:");scanf("%ld",&s);
fun(s,&t);
printf("The result is:%ld\n",t);
}
第7题
请改正函数fun中的错误,使它能得出正确的结果。
注意:部分源程序在文件MODll.C中,不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
第8题
下列给定的程序中,fun()函数的功能是:将p所指字符串中每个单词的最后一个字母改成大写(这里的“单词”是指有空格隔开的字符串)。例如,若输入:
I am a student to take the examination
则应输出:I aM A studenT tO take thE examinatioN
请改正程序中的错误,使它能得出正确的结果。
注童:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <ctype.h>
include <stdio.h>
void fun(char *p)
{
int k=0;
for (; *p;p++)
if (k)
{
/*************found**************/
if (p=='')
{
k=0;
/*************found**************/
*p=toupper(*(p-1));
}
}
else
k=1;
}
main()
{char chrstr[64];
int d;
clrscr();
printf("\nPlease enter an English sentence within 63 letters:");
gets(chrstr);
d=strlen(chrstr);
chrstr[d==' ';
chrstr[d+1]=0;
printf("\nBofore changing:\n %s",chrstr);
fun(chrstr);
printf("\nAfter changing:\n%s",chrstr);
}
第9题
给定程序MODll.C中函数fun的功能是:将s所指字符串中的字母转换为按字母序列的后续字母(但z转换为A,z转换为a),其他字符不变。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
第10题
下列给定程序中函数fun()的功能是:将长整型数中每一位上为偶数的数依次逆向取出,构成一个新数放在t中。高位在低位,低位在高位。例如当s中的数为25846513时,t中的数为6482。 请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
void fun(long S,long *t)
{
int d;
long sl=l,i=1;
*t=0;
while(s/i>0)
i=i*10;
i=i/10;
while(s>0)
{
d=s/i
/*************found*************/
if(d%2!=0)
{
/*************found*************/
t=d*sl+t;
sl*=l0;
}
S=S%i;
i=i/10;
}
}
main()
{
long S,t;
clrscr();
printf("\nPlease enter S:");
scanf("%ld",&s);
fun(S,&t);
printf("The result is:%ld\n",t);
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!