经典c语言笔试题Word文档格式.docx
- 文档编号:13345706
- 上传时间:2022-10-09
- 格式:DOCX
- 页数:28
- 大小:52.02KB
经典c语言笔试题Word文档格式.docx
《经典c语言笔试题Word文档格式.docx》由会员分享,可在线阅读,更多相关《经典c语言笔试题Word文档格式.docx(28页珍藏版)》请在冰豆网上搜索。
fileAcannotbeopened\n"
);
exit(0);
}
printf("
\nAcontentsare:
\n"
for(i=0;
(ch=fgetc(fp))!
=EOF;
i++)/*一个字符一个字符读*/
c[i]=ch;
putchar(c[i]);
num=i+1;
fclose(fp);
B"
fileBcannotbeopened\n"
\nBcontentsare:
i++)
c[num+i]=ch;
putchar(c[num+i]);
NUM=num+i+1;
for(k=0;
k<
NUM-1;
k++)/*冒泡排序*/
for(j=0;
j<
NUM-k-1;
j++)
if(c[j]>
c[j+1])
t=c[j];
c[j]=c[j+1];
c[j+1]=t;
}
\nCfileis:
fp=fopen("
C"
w"
i<
NUM;
putc(c[i],fp);
/*将字符一个个写入文件中*/
putchar(c[i]);
/*一个个输出字符*/
return1;
}
86.有一浮点型数组A,用C语言写一函数实现对浮点数组A进行降序排序,并输出结果,要求要以数组A作为函数的入口.(建议用冒泡排序法)
voidBubbleSort(intarr[],intn)
inti,j;
intexchange=1;
//交换标志,提高算法效率;
inttemp;
for(i=0;
n-1;
exchange=0;
//本趟排序开始前,交换标志应为假
for(j=0;
n-i-1;
if(arr[j+1]>
arr[j])
temp=arr[j+1];
arr[j+1]=arr[j];
arr[j]=temp;
exchange=1;
//发生了交换,故将交换标志置为真
if(!
exchange)//本趟排序未发生交换,提前终止算法
return;
intarr[5]={1,4,2,6,5};
inti;
BubbleSort(arr,5);
aftersort,arris:
5;
%3d"
arr[i]);
return1;
77.写出二分查找的代码:
Intbinary_search(int*arr,intkey,intsize)
Intmid;
Intlow=0;
Inthigh=size-1;
While(low<
=high)
Mid=(low+high)/2;
If(arr[mid]>
key)
High=mid-1;
ElseIf(arr[mid]<
Low=mid+1;
Else
Returnmid;
Return-1;
补充1:
用帅选法查找100之内的质数
#include<
iostream>
usingnamespacestd;
#defineN
100
intmain()
/*0~100共101个数*/
intsieve[N+1];
//step1:
初始化(sieve[i]=0表示不在筛中,即不是质数;
1表示在筛中)
sieve[0]=sieve[1]=0;
for(inti=2;
i<
=N;
i++)
sieve[i]=1;
//step2:
偶数(2的倍数)肯定不是质数,所以应该先筛除
for(i=2;
=N/2;
sieve[i*2]=0;
intp=2;
//第一个质数是2
//step3:
从sieve中删去P的倍数
while(p*p<
=N)
p=p+1;
//选下一个p
while(sieve[p]==0)
p++;
intt=p*p;
ints=2*p;
/*质数与质数之和包含合数,但质数于合数之和必为质数,提高算法效率*/
while(t<
sieve[t]=0;
//删除
t=t+s;
//step4:
输出结果
for(i=2;
if(sieve[i]!
=0)
cout<
<
"
"
;
《《《《链表操作考察》》》》
87、实现双向链表删除一个节点P,在节点P后插入一个节点,写出这两个函数。
//删除操作
StatusListDelete_DuL(DuLinkList&
L,int
i,ElemType&
e)
if(!
(p=GetElemP_DuL(L,i)))
return
ERROR;
//容错判断;
e=p->
data;
p->
prior->
next=p->
next;
next->
prior=p->
pror;
free(p);
p=NULL;
//勿忘,否则内存泄露
returnOK;
//插入操作
StatusListInsert_DuL(DuLinkList&
L,inti,ElemType&
e)
(s=(DuLinkList)malloc(sizeof(DuLNode))))
/*assert((s=(DuLinkList)malloc(sizeof(DuLNode)))!
=NULL)*/
s->
data=e;
prior=p;
next->
prior=s;
next=s;
OK;
88、把一个链表反向。
//链表头插法;
intre_Link(LinklistH)
Linklistp=H->
next,q;
H->
next=NULL;
while(p!
=NULL)
q=p;
p=p->
q->
next=H->
next=q;
return0;
《《《《strcpy和memcpy》》》》
76.已知strcpy函数的原型是char*strcpy(char*strDest,constchar*strSrc);
其中strDest是目的字符串,strSrc是源字符串。
(1)不调用C++/C的字符串库函数,请编写函数strcpy。
char*stringcpy(char*Des,constchar*Src)
assert((Des!
=NULL)&
&
(Src!
=NULL));
char*address=Des;
while((*Des++=*Src++)!
='
\0'
returnaddress;
断言assert是一个宏,该宏在<assert>中,
当使用assert时候,给他个参数,即一个判读为真的表达式。
预处理器产生
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 经典 语言 笔试
![提示](https://static.bdocx.com/images/bang_tan.gif)