题目
()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]设有定义 #define ITEM struct item #define SIZE sizeof(ITEM) ITEM { int num; ITEM *next; }; ITEM *head=NULL; 下述函数定义实现按插表尾形式(即每一新表元素插入至当前所生成链表的表尾之后)生成一个正向线性链表。最后指向所生成链表表头的指针作为函数值返回。为生成一个线性链表,要求输入一批整型数据,并以-1作为结束标志。请填空完善程序。 ITEM *gene(ITEM *head) { ITEM *temp,*tail;/*tail指向当前链表尾结点*/ int intno; printf("Enter integer NO.,-1 to stop:\n"); scanf("%d",&intno); while (intno!=-1) { temp=(____(1)_____)malloc(SIZE); temp->num=intno; if (head==_____(2)_____) /*空表*/ { head=temp; tail=______(3)______; } else /*非空表*/ { ____(4)_______=temp; tail=temp; } scanf("%d",&intno); } return (_______(5)_______);
第1题
第2题
第3题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【程序2.1说明】
求所有满足如下条件的三位数:它除以11得的商等于它各位数字的平方和。例如 550,除以11商为50,50=52+52+02。
【程序2.1】
void main()
{
int i, j,n,s;
for(i=100;i<=999;i++)
{
n=i;
j=n/11;
s=0;
while((1))
{
(2)
n/=10;
}
if((3))
printf("%d\t",i);
}
}
【程序2.2说明】
本程序输入一字符串,将其中的大写字母改变成小写字母。
【程序2.2】
void main()
{
int i=0;
char s[120];
scanf("%s",s);
while((4))
{
if((5))
s[i]=s[i]- 'A'+'a';
i++;
}
printf("%s\n",s);
}
第4题
阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。
【说明2.1】
以下C语言函数用二分插入法实现对整型数组a中n个数的排序功能。
【函数2.1】
void fun1 (int a[])
{ int i,j,k,r,x,m;
for(i=2;i<=n;i++)
{ (1);
k=1;r=i-1;
while(k<=r)
{ m=(k+r)/2;
if(x<a[m])r=m-1;
else (2);
}
for(j=i-1;j>=k;j--)
a[j+l]=a[j];
(3);
}
}
【说明2.2】
以下程序可以把从键盘上输入的十进制数(long型)以二~十六进制形式输出。
【程序2.2】
include<stdio.h>
main()
{ charb[16]={'0','l','2','3 ,4,'5','6','7','8','9','A','B','C','D','E','F'};
int c[64],d,i=0,base;
long n;
printf("enter a number:\n");
scanf("%1d",&n);
printf("enter new basc:\n");
scanf("%d", &base);
do
{ c[i]=(4);
i++; n=n/base;
} while(n!=0);
printf("transmite new base:\n");
for(--i;i>=0;--i)
{ d=c[i];
printf("%c",(5));
}
}
第5题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明1]
本程序输入一字符串,并将其中的大写字母变成小写字母。
[C函数1]
include<stdio.h>
void main()
{ int i=0;
char s[120];
printf("Enter a string.\n");
scanf("%s",s);
while((1) ){
if((2) )
s[i]=s[i]-'A'+'a';
i++;
}
printf("%s\n",S);
}
[说明2]
本程序用二分法,在已按字母次序从小到大排序的字符数组list[len]中,查找字符c,若c在数组中,函数返回字符c在数组中的下标,否则返回-1。
[C函数2]
int search(char list[],char c,int len)
(intlow=0,high=len-1,k;
while((3) );
k=(10w+high)/2;
if((4) ) return k;
else if((5) )high=k-1;
else low=k+1;
return -1;
}
第6题
阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【说明】
下面的程序构造一棵以二叉链表为存储结构的二叉树算法。
【函数】
BTCHINALR *createbt (BTCHINALR *bt )
{
BTCHINALR *q;
struct node1 *s [30];
int j,i;
char x;
printf ("i,x =" ); scanf ("%d,%c",&i,&x );
while (i!=0 && x!='$')
{ q = (BTCHINALR* malloc (sizeof (BTCHINALR )); //生成一个结点
(1);
q->1child = NULL;
q->rchild = NULL;
(2);
if((3);)
{j=i/2 //j为i的双亲结点
if(i%2==0
(4) //i为j的左孩子
else
(5) //i为j的右孩子
}
printf ("i,x =" ); scanf ("%d,%c",&i,&x ); }
return s[1]
}
第7题
阅读以下说明和C语言函数,将应填入(n)处的语句写在对应栏内。
【说明】
下面的程序构造一棵以二叉链表为存储结构的二叉树。
【函数】
BitTree *createbt(BitTree *bt)
{
BitTree *q;
struct node *s[30];
int j,i;
char x;
printf("i,x=");
scant("%d,%c",&i,&x);
while(i!=0 && x!='$')
{
q=(BitTree *}malloc(sizeof(BitTree));//生成一个结点
(1);
q->lchild=NULL;
q->rchild=NULL;
(2) ;
if ((3))
{
j=i/2; // j为i的双亲结点
if(i%2==0)
(4); //i为j的左孩子
else
(5); //i为j的右孩子
}
printf("i,x=");
scanf("%d,%c",&i,&x);
}
return s[i];
}
第8题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【说明】
编写程序,生成一个新文本文件,它由一个已知文本文件的所有偶数行组成。要求已知文本文件名和新文本文件名均从键盘输入。请填空完善程序。
【C语言程序】
include<stdio.h>
main()
{
FILE *oldf,*newf;
char ch,fname[20];
int i;
do{
printf("Enter name of existed text file to be read:");
scanf("%s",fname);
if((oldf=fopen(fname,"r"))==NULL)
printf("File %s can't open!\n",fname);
}while(oldf==NULL);
do{
printf("Enter mane of new text file to be written:");
scanf("%s",fname);
if(((1)==NULL)
printf("File %s can't open!\n",fname);
}while((2));
i=1;
while(!feof(oldf))
{
while((ch=fgetc(oldf))!=(3))
{
if(i%2==(4))
fputc(ch,newf);
}
fputc('\n',newf);
(5);
}
fclose(oldf);
fclose(newf);
}
第9题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【说明】
编写程序,利用带参数的主函数main(),实现二进制文件的复制。比如,若该程序已生成可执行文件filebin.exe,在DOS操作系统命令状态下键入如下命令行:
filebin f0.fil f1.fil
则实现将已存在的二进制文件f1.fil依原样复制给名为f0.fil的二进制文件。
【函数】
include<stdio.h>
void fcopy(FILE *fout, FILE *fin)
{
char k;
do{
k=fgetc((1));
if(feof(fin))
break;
fputc((2));
}while(1);
}
void main(int argc,char *argv[])
{
FILE *fin,*fout;
if(argc!=(3))
return;
if((fin=fopen(argv[2],"rb"))==NULL)
return;
fout=(4);
fcopy((5));
fclose(fin);
fclose(fout);
}
第10题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【程序2.1说明】
已知一个排好序的数组,现输入一个数,要求按原来的顺序规律,将它插入到数组中。
【程序2.1】
include <stdioh>
define N 100
void main()
{
float a[N+l],x;
int i,p;
printf("输入已经排好序的数列: ");
for(i=0; i<N; i++)
scanf(%f",&a[i]);
printf("输入要插入的数:");
scanf("%f",&x);
for(i=0,p=N; i<N; i++)
if(x<a[i])
{
(1)
break;
}
for(i=N-1; i>=p; i--)
(2)
(3)
for(i=0; i<=N; i++)
prinff("%f\t",a[i]);
}
【程序2.2说明】
本程序用变量count统计文件中字符的个数。
【程序2.2】
include <stdio.h>
include <stdlib.h>
void main()
{
FILE *fp;
long count=0;
if((fp=fopen("letter.txt","r"))==NULL)
{
printf("can not open file\n");
exit(0);
}
while(!feof(fp))
{
(4)
count++;
}
printf("count=%d\n",count);
(5)
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!