题目
例如,若输入“Ab,cD”,则输出“AB,CD”。
请改正程序中的错误,使它能得出正确的结果。
注意:部分源程序在文件MODIl.C中,不得增行或删行,也不得更改程序的结构!
第1题
下列给定程序中,函数fun()的作用是,将字符串tt中的大写字母都改为对应的小写字母,其他字符不变。例如,若输入"Ab,cD",则输出"ab, cd"。
请改正函数fun()中的错误,使它能得出正确的结果。
注童:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <string.h>
include <conio.h>
char *fun (char tt[])
{
int i;
for(i=0; tt[i]; i++)
/**************found**************/
{ if(('A' <=tt[i]||(tt[i]<='z' ))
tt[i]+=32; }
return(tt);
}
main()
{int i;
char tt[81];
clrscr();
printf("\nPlease enter a string:");
gets(tt);
printf("\nThe result string is:\n %s", fun(tt));
}
第2题
下列给定程序中,函数fun()的作用是:将字符串tt中的小写字母都改为对应的大写字母,其他字符不变。例如,若输入“edS,dAd”,则输出“EDS,DAD”。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <string.h>
include <conlo.h>
/*************found*************/
char fun(char tt[ ])
{
int i;
for(i=0;tt[i];i++)
{
/*************found*************/
if((tt[i]>='A')&&(tt[i]<='2'))
tt[i]-=32;
}
return(tt);
}
main()
{
int i;
char tt[81];
clrscr();
printf("\nPlease enter a string:");
gets(tt);
printf("\nThe result string iS:/n%s", fun(tt));
}
第3题
下列给定程序中,函数fun()的功能是:将str所指字符串中的字母转换为按字母序列的后续字母(Z转换A,z转换a),其他字符不变。
请修改函数fun()中的错误,得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
第4题
下列给定程序中,函数fun()的功能是:将P所指字符串中的所有字符复制到b中,要求在每复制3个字符之后插入1个空格。
例如,若给a输入字符串:“ABCDEFGHIJK”,调用函数后,字符数组b中的内容为:“ABC DEF GHI JK”。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
第5题
●试题四
请补充函数fun(),该函数的功能是将字符串tt中的大写字母都改为对应的小写字母,其他字符不变。例如,若输入"Are you come from Sichuan?",则输入"are you come from sichuan?"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char *fun(char tt[])
{
int i;
for(i=0;tt[i];i++)
{
if((tt[i]>=′A′)&&((1) ))
(2) ;
}
return ((3) ) ;
}
main()
{
char tt[81];
printf("\nPlease enter a string:");
gets(tt);
printf("\nThe result string is: \n%s",
fun(tt));
}
第6题
下列给定程序中,函数fun()的功能是:对N名学生的学习成绩,按从高到低的顺序找出前m(m≤10)名学生来,并将这些学生数据存放在一个动态分配的连续存储区中,此存储区的首地址作为函数值返回。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<mallo
C.h>
#include<string.h>
#include<conio.h>
#define N 10
typedef struct ss
{
char num[10];
int order;
}STU;
STU *fun(STU a[], int m)
{
STU b[N],*tt;
int i,j,k;
(1) ;
for(i=0; i<N; i++)
b[i]=a[i];
for (k=0;k<m;k++)
{
for(i=j=0;i<N;i++)
if ((2) )
j=i;
tt[k]=b[j];
b[j].order=0;
}
return (3) ;
}
outresult(STU a[],FILE *pf)
{
int i;
for(i=0;i<N; i++)
fprintf(pf,"No=%s Mark=%d\n",
a[i].num,a[i].order);
fprintf(pf,"\n\n");
}
main()
{
STU [N]={{"A01",80},{"A02",79},
{"A03",66},{"A04",82},{"A05",87},
{"A06",93},{"A07",78},{"A08",60},
{"A09",85},{"A10",73}};
STU *p_order;
int i,m;
clrscr();
printf("*** The Origial data ***\n");
outresult(a, stdout);
printf("\nGive the numeber of the
students who have better score:");
scanf("%d",&m);
while (m>10)
{
printf("\nGive the number of the
studets who have better score:");
scanf("%d",&m);
}
p_order=fun(a,m);
printf("*** THE RESULT ***\n");
printf("*** The top students ***\n");
for(i=0; i<m; i++)
printf(" %s %d\n",
p_order[i].num,p_order[i].order);
free(p_order);
}
第7题
下列给定程序中,函数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);
}
第8题
下列给定程序中,函数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 ");
}
第9题
请编写一个函数void fun(char*ss),其功能是:将字符串 ss中所有下标为偶数位置上的字母转化为大写(若该位置上不是字母,则不转换)。
例如,若输入abc4Efg,则应输出AbC4EfG。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio. h>
include<stdio. h>
void fun (char *ss)
{
}
main ()
{
char tt[51];
clrscr ();
printf("Please enter an character string
within 50 characters:\n");
gets (tt);
printf ("\n\nAfter changing, the string\n
%s", tt);
fun (tt);
printf("\nbecomes\n \%s",tt);
}
第10题
下列给定程序中函数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);
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!