方案设计题 请编写函数fun,其功能是:计算并输出给定数组(长度为9)中每相邻两个元素的平均值的平方根之和。
例如,若给定数组中的9个元素依次为1210、3410、410、230、340、450、180、310、110,则输出应为S=35.951014。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<math.h>
double fun(double x[9])
{
}
main()
{
double s,a[9]={12.0,34.0,4.0,23.0,34.0,45.0,18.0,3.0,11.0};
int i;
printf('\nThe original data is:\n');
for(i=0;i<9;i++)
printf('%6.1f',a[i]);
printf('\n\n');
s=fun(a);
printf('S=%f\n\n',s);
}
填空题
给定程序中函数fun的功能:计算形参x所指数组中N个数的平均值(规定所有数均为正数),作为函数值返回;并将大于平均值的数放在形参y所指数组中,在主函数中输出。
例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为30.500000。
主函数中输出:46 32 40 45 48。
请在程序的下划线处填入正确的内容,并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.c中,不得增行或删行,也不得更改程序的结构!
给定源程序如下:
#include stdlib.h
#include stdio.h
#define N 10
double fun(double x[],double *y)
{ int i,j; double av;
/**********found**********/
av=__1__;
/**********found**********/
for(i=0; iN; i++) av = av + __2__;
for(i=j=0; iN; i++)
/**********found**********/
if(x[i]av) y[__3__]= x[i];
y[j]=-1;
return av;
}
main()
{ int i; double x[N] = {46,30,32,40,6,17,45,15,48,26};
double y[N];
for(i=0; iN; i++) printf('%4.0f ',x[i]);
printf('\n');
printf('\nThe average is: %f\n',fun(x,y));
for(i=0; y[i]=0; i++) printf('%5.0f ',y[i]);
printf('\n');
}
填空题 给定程序中,函数fun的功能是:将形参s所指字符串中的所有数字字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数值返回。
例如,s所指字符串为:asd123fgh543df,处理后新字符串为:123543asdfghdf。
请在程序的下划线处填入正确的内容,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
char *fun(char*s)
{int i,j,k,n;char*p,*t;
n=strlen(s)+1;
t=(char*)malloc(n*sizeof(char));
p=(char*)malloc(n*sizeof(char));
j=0;k=0;
for(i=0;i<n;i++)
{if(isdigit(s[i])){
/**********found**********/
p[______]=s[i];j++;}
else
{t[k]=s[i];k++;}
}
/**********found**********/
for(i=0;i<______;i++)
p[j+i]=f[i];
p[j+k]=0;
/**********found**********/
return______;
}
main()
{char s[80];
printf('Please input:');
scanf('%s',s);
printf('\nThe result is;%s\n',fun(s));
}
填空题 请补充main()函数,该函数的功能是:打印出满足个位的数字、十位上的数字和百位上的数字都相等的所有3位数。
本题的结果为:111 222 333 444 555 666 777 888 999。
注意:部分源程序如下。
请勿改动main()函数和其他函数中的任何内容,仅在main()函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
void main()
{
int a,b,c;
system('CLS');
for(a=1;a<10;a++)
for(b=1;b<10;b++)
for(c=1;c<10;c++)
{
if(______)
printf('%5d',______);
}
}
填空题下列给定程序中,函数fun的功能是计算下式:直到,并将计算结果作为函数值返回。例如,若形参e的值为le-3,函数的返回值为2985678。请在下划线处填入正确的内容,使程序得出正确的结果。注意:部分源程序给出如下。不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>doublefun(doublee){inti;doubles,x;/********found********/s=0;i=______;x=1.0;while(x>e){/********found********/______;/********found********/x=(20*i-1)/______;s=s+x;}returns;}main()(doublee=le-3;printf('\nTheresultis:%f\n',fun(e));}
填空题 给定程序中,函数fun的功能是:将形参指针所指结构体数组中的三个元素按num成员进行升序排列。
请在程序的下划线处填入正确的内容,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include <stdio.h>
typedef struct
{ int num;
char name[10];
}PERSON;
/**********found**********/
void fun(PERSON______)
{
/**********found**********/
______ temp;
if(std[0].num>std[1].num)
{ temp=std[0]; std[0]=std[1]; std[1]=temp;}
if(std[0].num>std[2].num)
{ temp=std[0]; std[0]=std[2]; std[2]=temp;}
if(std[1].num>std[2].num)
{ temp=std[1]; std[1]=std[2]; std[2]=temp;}
}
main()
{ PERSON std[]={ 5,'Zhanghu',2,'WangLi', 6,'LinMin'};
int i;
/**********found**********/
fun(______);
printf('\nThe result is:\n');
for(i=0;i<3;i++)
printf('%d,%s\n',std[i].num,std[i].name);
}
填空题 给定程序中,函数fun的功能是:将形参s所指字符串中所有ASCII码值小于97的字符存入形参t所指字符数组中,形成一个新串,并统计出符合条件的字符个数作为函数值返回。
例如,形参s所指的字符串为:Abc@1x56*,程序执行后t所指字符数组中的字符串应为:A@156*。
注意:不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
int fun(char *s,char *t)
{int n=0;
while(*s)
{if(* s<97){
/*********found*********/
*(t+n)=______;n++;}
/*********found*********/
______;
}
*(t+n)=0;
/*********found*********/
return ______;
main()
{char s[81],t[81];int n;
printf('\nEnter a string:\n');
gets(s);
n=fun(s,t);
printf('\nThere are % d letter which ASCII code is less than 97:% s\n',n,t);
}
填空题
给定程序中函数fun的功能:将形参n中,各位上为偶数的数取出,并按原来从高位到低位相反的顺序组成一个新的数,并作为函数值返回。
例如,输入一个整数27638496,函数返回值为64862。
请在程序的下划线处填入正确的内容,并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.c中。不得增行或删行,也不得更改程序的结构!
给定源程序如下:
#include stdio.h
unsigned long fun(unsigned long n)
{ unsigned long x=0; int t;
while(n)
{ t=n%10;
/**********found**********/
if(t%2==__1__)
/**********found**********/
x=__2__+t;
/**********found**********/
n=__3__;
}
return x;
}
main()
{ unsigned long n=-1;
while(n99999999||n0)
{ printf('Please input(0n100000000): '); scanf('%ld',n); }
printf('\nThe result is: %ld\n',fun(n));
}
填空题 请补充函数proc(),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:1 1 2 2 2 3 4 4 5 5 6 6 6 7 7 8 10 10。
删除后,数组中的内容应该是:1 2 3 4 5 6 7 8 10。
注意:部分源程序如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define M 80
int proc(int arr[],int n)
{
int i,t,j=0;
t=arr[0];
for(i=1;i<n;i++)
if(______)
;
else
{
______;
t=arr[i];
}
arr[j++]=t;
return j;
}
void main()
{
int arr[M]={1,1,2,2,2,3,4,4,5,5,6,6,6,
7,7,8,10,10},i,n=18;
printf('The original data:\n');
for(i=0;i<n;i++)
printf('%4d',arr[i]);
n=proc(arr,n);
printf('\n\nThe data after deleted;
\n');
for(i=0;i<n;i++)
printf('%4d',arr[i]);
printf('\n');
}
填空题
用筛选法可得到2~n(n<10000)的所有素数。方法:从素数2开始,将所有2的倍数从数表中删除(把数表中相应位置的值置成0);接着,从数表中找下一个非0数,并从数表中删去该数的所有倍数;依次类推,直到所找的下一个数等于n为止。这样会得到一个序列:
2,3,5,7,11,13,17,19,23,…
函数fun的作用:用筛选法找出所有小于等于n的素数,并统计素数的个数作为函数值返回。
请在程序的下划线处填入正确的内容,并把下划线删除,使程序得出正确的结果。
注意:源程序存入在文件BLANK1.C中,不得增选或删行,也不得更改程序的结构!
给定源程序如下:
#include stdio.h
int fun(int n)
{ int a[10000], i,j, count=0;
for (i=2; i=n; i++) a[i] = i;
i = 2;
while (in) {
/**********found**********/
for (j=a[i]*2; j=n; j+=___1___)
a[j] = 0;
i++;
/**********found**********/
while (___2___==0)
i++;
}
printf('\nThe prime number between 2 to %d\n', n);
for (i=2; i=n; i++)
/**********found**********/
if (a[i]!=___3___)
{ count++; printf( count%15?'%5d':'\n%5d',a[i]); }
return count;
}
main()
{ int n=20, r;
r = fun(n);
printf('\nThe number of prime is : %d\n', r);
}
填空题 下列给定程序中,函数fun的功能是:把形参a所指数组中的偶数按原顺序依次存放到a[0]、a[1]、a[2]…中,把奇数从数组中删除,偶数的个数通过函数值返回。
例如,若a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7,删除奇数后,a所指数组中的数据为:4、2、6、8,返回值为4。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#define N 9
int fun(int a[], int n)
{ int i,j;
j=0;
for (i=0; i<n; i++)
/*********found*********/
if(______==0) {
/*********found*********/
______ = a[i]; j++;
}
/*********found*********/
return______;
}
main()
{ int b[N]={9,1,4,2,3,6,5,8,7),i,n;
printf('\nThe original data:\n');
for(i=0; i<N; i++)
printf('%4d', b[i]);
printf('\n');
n = fun(b, N);
printf('\nThe number of even:%d\n', n);
printf ('\nThe even :\n');
for (i=0; i<n; i++)
printf('%4d', b[i]);
printf('\n');
}
填空题 给定程序中,函数fun的功能是将不带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include<stdio.h>
#include<stdlib.h>
#define N 5
typedef struct node {
int data;
struct node *next;
}NODE;
/***********found***********/
______*fun(NODE*h)
{NODE*p,*q,*r;
p=h;
if(p==NULL)
return NULL;
q=p->next;
p->next=NULL;
while(q)
{
/***********found***********/
r=q->______;
q->next=p;
p=q;
/***********found***********/
q=______;
}
return p;
}
NODE*creatlist(int a[])
{NODE*h,*p,*q;int i;
h=NULL;
for(i=0;i<N;i++)
{q=(NODE*)malloc(sizeof(NODE));
q->data=a[i];
q->next=NULL;
if(h==NULL)h=p=q;
else{p->next=q;p=q;)
}
return h;
}
void outlist(NODE*h)
{NODE*p;
p=h;
if(p==NULL)printf('The list is NULL!\n');
else
{printf('\nHead');
do
{printf('->%d',p->data);p=p->next;
}
while(p!=NULL);
printf('->End\n');
}
}
main()
{NODE*head;
int a[N]={2,4,6,8,10};
head=creatlist(a);
printf('\nThe original list:\n');
outlist(head);
head=fun(head);
printf('\nThe list after inverting:\n');
outlist(head);
}
填空题函数fun的功能:计算直到。若x=2.5,则函数值为1.917915。请在程序的下划线处填入正确的内容,并把下划线删除,使程序得出正确的结果。注意:源程序存放在文件BLANK1.c中。不得增行或删行,也不得更改程序的结构!给定源程序如下:#includestdio.h#includemath.hdoublefun(doublex){doublef,t;intn;f=1.0+x;/**********found**********/t=___1___;n=1;do{n++;/**********found**********/t*=(-1.0)*x/___2___;f+=t;}/**********found**********/while(___3___=1e-6);returnf;}main(){doublex,y;x=2.5;y=fun(x);printf('\nTheresultis:\n');printf('x=%-12.6fy=%-12.6f\n',x,y);}
填空题 给定程序中,函数fun的功能是:将形参s所指字符串中的数字字符转换成对应的数值,计算出这些数值的累加和作为函数值返回。
例如,形参s所指的字符串为:abs5def126jkm8,程序执行后的输出结果为:22。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int fun(char*s)
{int sum=0;
while(*s){
/**********found**********/
if(isdigit(*s))sum+=*s-______;
/**********found**********/
______;
}
/**********found**********/
return______;
}
main()
{char s[81];int n;
printf('\nEnter a string:\n\n');gets(s);
n=fun(s);
printf('\nThe result is: %d\n\n',n);
}
填空题 给定程序中,函数fun的功能是:判断形参s所指字符串是否是“回文”(Palindrome),若是,函数返回值为1;不是,函数返回值为0。“回文”是正读和反读都一样的字符串(不区分大小写字母)。
例如,LEVEL和Level是“回文”,而LEVLEV不是“回文”。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int fun(char *s)
{ char *lp, *rp;
/**********found**********/
lp=______;
rp=s+strlen(s)-1;
while((toupper(*lp)==toupper(*rp))(lp<rp)){
/**********found**********/
lp++; rp______;}
/**********found**********/
if(lp<rp)______;
else relurn 1;
}
main()
{ char s[81];
printf('Enter a string:'); scanf('%s', s);
if(fun(s)) printf('\n\'%s\' is a Palindrome.\n\n', s);
else printf('\n\'%s\'isn't a Palindrome.\n\n'. s);
}
填空题 函数fun的功能是:把形参a所指数组中的奇数按原顺序依次存放到a[0]、a[1]、a[2]、……中,把偶数从数组中删除,奇数个数通过函数值返回。例如:若a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7,删除偶数后a所指数组中的数据为:9、1、3、5、7,返回值为5。
请在程序的下划线处填入正确的内容,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include <stdio.h>
#define N 9
int fun(int a[],int n)
{ int i,j;
j=0;
for(i=0;i<n;i++)
/**********found**********/
if(a[i]%2==______)
{
/**********found**********/
a[j]=a[i];______;
}
/**********found**********/
return ______;
}
main()
{ int b[N]={9,1,4,2,3,6,5,8,7},i,n;
printf('\nThe original data :\n');
for(i=0; i<N; i++) printf('%4d',b[i]);
printf('\n');
n=fun(b,N);
printf('\nThe number of odd:%d\n',n);
printf('\nThe odd number:\n');
for (i=0; i<n; i++) printf('%4d',b[i]),
printf('\n');
}
填空题 给定程序的功能是调用fun函数建立班级通讯录。通讯录中记录每位学生的编号、姓名和电话号码。班级的人数和学生的信息从键盘读入,每个人的信息作为一个数据块写到名为myfile5.dat的二进制文件中。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构。
#include<stdio.h>
#include<stdlib.h>
#defineN 5
typedef struct
{int num;
char name[10];
char tel[10];
}STYPE;
void check();
/**********foun**********/
int fun(______*std)
{
/**********found**********/
______*fp;int i;
if((fp=fopen('myfile5.dat','wb'))==NULL)
return(0);
printf('\nOutput data to file!\n');
for(i=0;i<N;i++)
/**********foun**********/
fwrite(std[i],sizeof(STYPE),1,______);
fclose(fp);
return(1);
}
main()
{STYPE s[10]={{1,'aaaaa','111111'),{1,'bbbbb',
'222222'},{1,'ccccc','333333'),{1,'ddddd',
'444444'},{1,'eeeee','555555'));
int k;
k=fun(s);
if(k==1)
{printf('Succeed!');check();}
else
printf('Fail!');
}
void check()
{FILE*fp;int i;
STYPE s[10];
if((fp=fopen('myfile5.dat','rb'))==NULL)
{printf('Fail!!\n');exit(0);}
printf('\nRead file and output to screen:\n');
printf('\n num name tel\n');
for(i=0;i<N;i++)
{fread(s[i],sizeof(STYPE),1,fp);
printf('%6d %s %s\n',s[i].num,s[i].name,
s[i].tel);
}
fclose(fp);
}
填空题 请补充函数proc(),函数proc()的功能是求7的阶乘。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
long proc(int n)
{
if(______)
return(n*proc(______);
else if(______)
return 1;
}
void main()
{
int k=7;
printf('%d!=%ld\n', k, proc(k));
}
填空题 下列给定程序中,函数fun的功能是:将形参s所指字符串中的所有字母字符顺序前移,其他字符顺序后移,处理后将新字符串的首地址作为函数值返回。
例如,若s所指字符串为“asd123fgh543df”,处理后新字符串为“asdfghdf123543”。
请在下划线处填入正确的内容,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char*fun(char*s)
{int i,j,k,n;char*p,*t;
n=strlen(s)+1;
t=(char*)malloc(n*sizeof(char));
P=(char*)malloc(n*sizeof(char));
j=0;k=0;
for(i=0;i<n;i++)
{if(((s[i]>='a')&&(s[i]<='z'))||((s[i]>='A')&&(s[i]<='Z'))){
/********found********/
t[j]=______;j++;}
else
{p[k]=s[i];k++;}
}
/********found********/
for(i=0;i<______;i++)
t[j+i]=p[i];
/********found********/
t[j+k]=______;
return t;
}
main()
{char s[80];
printf('Please input:');
scanf('%s',s);
printf('\nThe result is:%s\n',fun (s));
}
填空题 从键盘输入一组无符号整数并保存在数组arr[N]中,以整数0结束输入,即第(N+1)个数是0,要求这些数的最大位数不超过4位,其元素的个数通过变量num传入函数proc()。请补充函数proc(),其功能是:从数组arr中找出个位和十位的数字之和大于5的所有无符号整数,结果保存在数组yy中,其个数由函数proc()返回。
例如,当arr[8]={13,1,205,252,2,333,4444,21},实际输入时,数与数之间用Enter键分开,bb[4]={252,333,4444}。
注意:部分源程序如下。
请勿改动函数main()和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define M 1000
int proc(int arr[],int bb[],int num)
{
int i,m=0;
int g,s;
for(i=0;i<num;i++)
{
g=______;
s=arr[i]/10%10;
if((g+s)>5)
______;
}
return______;
}
void main()
{
int arr[M];
int yy[M];
int num=0,m=0,i=0;
printf('Input number:\n');
do
{
scanf('%u',arr[num]);
}
while(arr[num++]!=0);
m=proc(art,yy,num);
printf('\nyy=');
for(i=0;i<m;i++)
printf('%u',yy[i]);
}
