1 2 3
4 5 6
7 8 9
交换后为:
3 2 1
4 5 6
9 8 7
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#define N 4
/**********found**********/
void fun(int ___1___ , int n)
{int i,s;
/**********found**********/
for(___2___; i++)
{s=t[i][i];
t[i][i]=t[i][n-i-1];
/**********found**********/
t[i][n-1-i]=___3___;
}
}
main()
{int t[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42, 21,33,10}, i, j;
printf("\nThe original array:\n");
for(i=0; i
{for(j=0; j
}
fun(t,N);
printf("\nThe result is:\n");
for(i=0; i
{for(j=0; j
}
}
解题答案:
/**********found**********/
void fun(int t[][N] , int n)
/**********found**********/
for(i=0;i
/**********found**********/
t[i][n-1-i]=s;
****************************************** [NextPage] 二、改错题:由N个有序整数组成的数列已放在一维数组中,给定程序MODI1.C中函数fun的功能是:利用折半查找算法查找整数m在数组中的位置。若找到,返回其下标值;反之,返回-1。
折半查找的基本算法是:每次查找前先确定数组中待查的范围:low和high
(low
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
给定源程序:
#include
#define N 10
/************found************/
void fun(int a[], int m)
{int low=0,high=N-1,mid;
while(low<=high)
{mid=(low+high)/2;
high=mid-1;
/************found************/
else If(m > a[mid])
low=mid+1;
else return(mid);
}
return(-1);
}
main()
{int i,a[N]={-3,4,7,9,13,45,67,89,100,180 },k,m;
printf("a数组中的数据如下:");
for(i=0;i
k=fun(a,m);
if(k>=0) printf("m=%d,index=%d\n",m,k);
else printf("Not be found!\n");
}
解题答案:
/************found************/
int fun(int a[],int m)
/************found************/
else if(m>a[mid])
******************************************
[NextPage] 三、程序题:假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:除了尾部的*号之外,将字符串中其它*号全部删除。形参p已指向字符串中最后的一个字母。在编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为:****A*BC*DEF*G*******,删除后,字符串中的内容应当是: ABCDEFG*******。
注意: 部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
void fun(char *a, char *p)
{
}
main()
{char s[81],*t;
void NONO ();
printf("Enter a string:\n");gets(s);
t=s;
while(*t)t++;
t--;
while(*t=='*')t--;
fun(s , t);
printf("The string after deleted:\n");puts(s);
NONO();
}
void NONO()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *in, *out ;
int i ; char s[81],*t ;
in = fopen("in.dat","r");
out = fopen("out.dat","w");
for(i = 0 ; i < 10 ; i++) {
fscanf(in, "%s", s);
t=s;
while(*t)t++;
t--;
while(*t=='*')t--;
fun(s,t);
fprintf(out, "%s\n", s) ;
}
fclose(in);
fclose(out);
}
参考答案:
void fun( char *a, char *p )
{
char *q=a;
int j=0;
while(*q && q
if(*q != '*') a[j++] = *q ;
q++ ;
}
while(*p) a[j++]=*p++;
a[j]=0;
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|