更多"改错题
下列给定程序中,函数fun( )的功能是逐个比较a,b两个字"的相关试题:
[简答题]改错题
下列给定程序中,函数fun( )的功能是逐个比较a,b两个字符串对应位置中的字符,把ASCII值小或相等的字符依次存放到c数组中,形成一个新的字符串。
例如:a中的字符串为fshADfg,b中的字符串为sdAEdi,则c中的字符串应为fdAADf。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
void fun(char *p,char *q,char *c)
{ int k=0;
while(*p||*q)
/**********************found***********************/
{ if (*p<=*q)
c[k]=*q;
else c[k]=*p;
if(*p) p++;
if(*q) q++ ;
/**********************found***********************/
k++
}
}
main( )
{ char a[10]="fshADfg",b[10]="sdAEdi",c[80]={’’/0’’};
fun(a,b,c);
printf("The string a:"); puts(a);
printf("The string b:"); puts(b);
printf("The result :"); puts(c);
}
[简答题]改错题
下列给定程序中,函数fun( )的功能是:依次取出字符串中所有的字母,形成新的字符串,并取代原字符串。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
void fun(char *s)
{
int i,j;
for(i=0,j=0; s[i]!= ’’/0’’; i++)
/**********************found***********************/
if((s[i]>= ’’A’’&&s[i]<= ’’Z’’)&&(s[i]>= ’’a’’&&s[i]<= ’’z’’))
s[j++]=s[i];
/**********************found***********************/
s[j]= "/0";
}
main( )
{
char item[80];
clrscr( );
printf("/nEnter a string: ");
gets(item);
printf("/n/nThe string is:/%s/n",item);
fun(item);
printf("/n/nThe string of changing is :/%s/n",item);
}
[简答题]改错题
下列给定程序中,函数fun( )的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码降序排序后输出。
例如:输入dafhc,则应输出hfdca。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
/**********************found***********************/
int fun(char t[ ])
{
char c;
int i,j;
for(i=0;i
[填空题]下列给定程序中,函数fun( )的功能是逐个比较a,b两个字符串对应位置中的字符,把ASCII值小或相等的字符依次存放到c数组中,形成一个新的字符串。
例如:a中的字符串为fshADfg,b中的字符串为sdAEdi,则c中的字符串应为fdAADf。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <strinq.h>
void fun(char *p,char *q,char *c)
int k=0;
while(*p || *q)
/**********found**************/
if (*p<=*q)
c[k]=*q;
else c[k]:*p;
if(*p) p++;
if(*q) q++;
/**+**********found**************/
k++
main( )
char a[10]="fshADfg",b[10]="sdAEdi",
c[80]=’/0’);
fun(a,b,c);
printf("The string a:");puts
- (a);
printf("The string b:");puts - (b);
printf("The result:");puts - (c);
[简答题]改错题
下列给定程序中,函数fun( )的功能是计算并输出high以内的素数之和。high由主函数传给fun( )函数。若high的值为100,则函数的值为1060。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
#include
int fun(int high)
{
int sum=0,n=0, j, yes;
while(high>=2)
{
yes = 1;
for(j=2; j<=high/2; j++)
/**********************found***********************/
ifhigh%j==0
{
yes=0;
break;
}
/**********************found***********************/
if(yes==0)
{
sum+=high;
n++;
}
high--;
}
return sum;
}
main( )
{
clrscr( );
printf("%d/n",fun(100));
}
[填空题]下列给定程序中,函数fun( )的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为abcdabfab,t所指字符串的内容为ab,则函数返回整数3。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
int fun (char *s, char *t)
{int n; char *p, *r;
n=0;
while(*s)
{p=s;
r=t;
while (*r)
/**************found**************/
if(*r==*p) {r++; p++}
else break;
/*************found**************/
if(r==’/0’)
n++;
s++;
}
return n;
}
main( )
{char s[100], t[100]; int m;
clrscr( );
printf("/nPlease enter string s: ");
scanf ("%s",s);
printf("/nPlease enter substring t: ");
scanf ("%s",t);
m=fun (s,t);
printf("/nThe result is: m=%d/n", m);
}
[简答题]改错题
下列给定程序中函数fun( )的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
long fun(long num)
{
/**********************found***********************/
long k=1;
do
{
k+=(num%10)*(num%10);
num/=10;
/**********************found***********************/
}while(num)
return (k);
}
main( )
{
long n;
clrscr( );
printf("/Please enter a number:");
scanf("%ld",&n);
printf("/n%ld/n",fun(n));
}
[简答题]改错题
下列给定程序中,函数fun( )的功能是找出100~n(不大于1000)之间百位数字加十位数字等于个位数字的所有整数,把这些整数放在s所指的数组中,个数作为函数值返回。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#define N 100
int fun(int *s, int n)
{
int i,j,k,a,b,c;
j=0;
for(i=100; i 1000);
num= fun(a,n);
printf("/n/nThe result :/n");
for(i=0; i
[简答题]改错题
下列给定程序中,函数fun( )的功能是根据整型形参m,计算如下公式的值。
y=1-1/(2×2)+1/(3×3)-1/(4×4)+…+(-1)(m+1)/(m×m)
例如:m中的值为5,则应输出0.838611。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
double fun(int m)
{ double y=1.0;
/**********************found***********************/
int j=1;
int i;
for(i=2; i<=m; i++)
{
j=-1*j;
/**********************found***********************/
y+=1/(i * i);
}
return(y);
}
main( )
{
int n=5;
clrscr( );
printf("/nThe result is %lf/n" ,fun(n));
}
[填空题]给定程序中,函数fun的功能是:求出形参ss所指字符串数组中最长字符串的长度,其余字符串左边用字符*补齐,使其与最长的字符串等长。字符串数组中共有M个字符串,且串长小于N。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <string.h>
#defineM 5
#defineN 20
void fun (char (*ss)[N])
inti, j, k=0, n, m, len;
for(i=0; i<M; i++)
len=strlen(ss[i]);
if(i==0)n=len;
if (len>n)
/******************found*******************/
n=len; (1) =i;
for(i=0; i<M; i++)
if(if=k)
m=n;
len=strlen(ss[i]);
/******************found*******************/
for (j= (2) ; j>=0; j--)
ss[i][m--]=ss[i][j];
for (j=0; j<n-len; j++)
/******************found*******************/
(3) =’*’;
main( )
char ss[M][N]="shanghai", "guangzhou",
"beijing", "tianjin", "chongqing");
int i;
printf("/nThe original strings are:/n");
for(i=0; i<M; i++)