题目
例如,若给a输入字符串:ABCDEFGKHHK,调用函数后,字符数组b中的内容为:ABC DEF GHI JK。请改正程序中的错误,使它能得出正确的结果。
注意:部分源程序在文件MODll.C中,不得增行或删行,也不得更改程序的结构。
第1题
下列给定程序中,函数fun()的功能是:将P所指字符串中的所有字符复制到b中,要求在每复制3个字符之后插入1个空格。
例如,若给a输入字符串:“ABCDEFGHIJK”,调用函数后,字符数组b中的内容为:“ABC DEF GHI JK”。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
第2题
下列给定程序中,函数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 ");
}
第3题
下列给定的程序中,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);
}
第4题
下列给定程序中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);
}
第5题
下列给定的程序中,函数fun()的功能是;将s所指字符串中出现的n所指字符串全部替换成t2所指字符串,所形成的新的字符串放在w所指的数组中。在此处,要求t1和t2所指字符串的长度相同。例如:当s所指字符串中所指的内容为 abcdabfab,t1所指字符串中的内容为ab,t2所指字符串中的内容为99时,结果在w所指的数组中的内容应为99cd99f99。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
/*************found**************/
int fun (char *s, char *t1, char *t2, char *w)
{
int i; char *p,*r,*a;
strcpy(w,s);
while (*w)
{p=w; r=t1;
/*************found**************/
while (r)
if (*r= =*p) {r++;p++;}
else break;
if (*r= ='\0')
{a=w; r=t2;
/*************found**************/
while (*r){*a=*r;a++;r++}
w+=strlen(t2);
}
else w++;
}
}
main()
{char s[100],t1[100],t2[100],w[100];
clrscr();
printf("\nPlease enter string S: ");
scanf("%s",s);
printf("\nPleaseentersubstring t1: ");
scanf ("%s", t1);
printf("\nPlease enter substring t2: ");
scanf ("%s",t2);
if (strlen(t1)= =strlen(t2))
{
fun (s,t1,t2,w);
printf("\nThe result is : %s\n",w);
}
else printf("Error : strlen(t2)\n");
}
第6题
下列给定程序中,函数fun()的功能是:将m(1≤m≤10)个字符串连接起来,组成一个新串,放入pt所指字符串中,例如:把3个串abc,CD,EF串联起来,结果是abcCDEF。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <string.h>
include <stdio.h>
/*************found**************/
int fun(char str[] [10],int m, char *pt)
{ int k,q,i,j=0;
for(k=0;k<m;k++)
{ q=strlen(str[k]);
j+=q;
for(i=0;i<q;i++)
/*************found**************/
pt[i]=str[k,i];
pt+=q;
pt[0] =0;
}
pt-=j;
}
main ()
{ int m, h;
char s[10] [10],p[120];
clrscr ();
printf("\nPlease enter m: ");
scanf("%d",&m); gets(s[0]);
printf ("\nPlease enter %d string:In ",m);
for(h=0;h<m;h++) gets(s[h]);
fun (s,m,p);
printf("\nThe result is :%s\n ",p);
}
第7题
下列给定程序中,函数fun()的功能是:将m(1≤m≤10)个字符串反着连接起来,组成一个新串,放入pt所指字符串中,例如:把3个串DEG,ac,df反着串联起来,结果是dfacDEG。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或者删行,也不得改变程序的结构!
试题程序:
include <conio.h>
include <string.h>
include <stdio.h>
void fun(char str[][10],int m,char *pt)
{
int k,q,i,j=0;
/*************found*************/
for(k=m;k>0;k--)
{
q=strlen(str[k]);
j+=q;
for(i=0;i<q;i++)
pt[i]=str[k][i];
pt+=q;
pt[0]=0;
}
/*************found**************/
pt=j;
}
main()
{int m,h;
char s[10][10],p[120];
clrscr();
printf("\nPlease enter m:");
scanf("%d",& m);
printf("\nPlease enter%d string:\n",m);
gets(s[0]);
for(h=0;h<m;h++)
gets(s[h]);
fun(S,m,p);
printf("/nThe result iS:%s\n",p);
}
第8题
下列给定程序中,函数fun()的功能是:在字符串str中找出ASCII码值最大的字符,将其放在第一个位置上,并将该字符前的原字符向后顺序移动。例如,调用fun()函数之前给字符串输入ABCDeFGH,调用后字符串中的内容为 eABCDFGH。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
/***************found************/
fun(char *p)
{ char max, *q;int i=0;
max=p[i];
while (p[i]!=0)
{if (max<p[i])
{
/***************found************/
p = q +i;max=p[i];
}
i++;
}
/***************found************/
while (q<p)
{*q=*(q-1);
q--;
}
p[0]=max;
}
main()
{ char str[80];
printf("Enter a string: "); gets(str);
printf("\nThe original string: ");
puts(str);
fun(str);
printf("\nThe string after moving: ");
puts(str); printf("\n\n");
}
第9题
下列给定程序中,函数fun()的功能是:在字符串str中找出ASCII码值最小的字符,将其放在第一个位置上,并将该字符前的原字符向后顺序移动。例如,调用fun()函数之前给字符串输入fagAgBDh,调用后宁符串中的内容为AfaggBDh。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
/*************found************/
void fun(char p)
{
char min,*q;
int i=0;
min=p[i];
while(p[i]!=0)
{
if(min>p[i])
{
/*************found*************/
p=q+i;
min=p[i];
}
i++;
}
while(q>p)
{*q=*(q-1);
q--;
}
p[0]=min;
}
main()
{
char str[80];
printf("Enter a string:");
gets(str);
printf("\nThe original string:");
puts(str);
fun(str);
printf("\nThe string after moving:");
puts(str);
printf("\n\n");
}
第10题
下列给定程序中,函数fun()的功能是;求S的值。设 S=(22/1*30))*(42/(3*5))*(62/(5*7))*…*(2k)2/((2k-1)*(2k+1))
例如,当k为10时,函数的值应为1.533852。
请改正程序中的错误,使它能得出正确的结果。
注童;不要改动main 函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio. h>
include <stdio. h>
include <math.h >
/**************found***************/
fun (int k)
{ iht n; float s, w, p, q;
n=1;
s=1.0;
while (n<=k)
{ w=2. 0*n;
p=w-1.0;
q=w+1.0;
s=s*w*w/p/q;
n++;
}
/***************found**************/
return s
}
main()
{ clrscr ();
printf ("%f\n ", fun (10));
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!