c 高级面试题目.docx
- 文档编号:23985406
- 上传时间:2023-05-23
- 格式:DOCX
- 页数:11
- 大小:15.05KB
c 高级面试题目.docx
《c 高级面试题目.docx》由会员分享,可在线阅读,更多相关《c 高级面试题目.docx(11页珍藏版)》请在冰豆网上搜索。
c高级面试题目
c高级面试题目
1、有一分数序列:
1/2,1/4,1/6,1/8,用函数调用的方法,求此数列前20项的和
#includestdio.h
doublegetValue()
{
doubleresult=0;
inti=2;
while(i42)
{
result+=1.0/i;//一定要使用1.0做除数,不能用1,否则结果将自动转化成整数,即0.000000
i+=2;
}
returnresult;
}
intmain()
{
printf(resultis%f\n,getValue());
system(pause
return0;
}
2、有一个数组a[1000]存放0--1000;要求每隔二个数删掉一个数,到末尾时循环至开头继续进行,求最后一个被删掉的数的原始下标位置。
以7个数为例:
{0,1,2,3,4,5,6,7}0--1--2(删除)--3--4--5(删除)--6--7--0(删除),如此循环直到最后一个数被删除。
方法1:
数组
#includeiostream
usingnamespacestd;
#definenull1000
intmain()
{
intarr[1000];
for(inti=0;i1000;++i)
arr[i]=i;
intj=0;
intcount=0;
while(count999)
{
while(arr[j%1000]==null)
j=(++j)%1000;
j=(++j)%1000;
while(arr[j%1000]==null)
j=(++j)%1000;
j=(++j)%1000;
while(arr[j%1000]==null)
j=(++j)%1000;
arr[j]=null;
++count;
}
while(arr[j]==null)
j=(++j)%1000;
coutjendl;
return0;
}方法2:
链表
#includeiostream
usingnamespacestd;
#definenull0
structnode
{
intdata;
node*next;
};
intmain()
{
node*head=newnode;
head-data=0;
head-next=null;
node*p=head;
for(inti=1;i1000;i++)
{
node*tmp=newnode;
tmp-data=i;
tmp-next=null;
head-next=tmp;
head=head-next;
}
head-next=p;
while(p!
=p-next)
{
p-next-next=p-next-next-next;
p=p-next-next;
}
coutp-data;
return0;
}
方法3:
通用算法
#includestdio.h
#defineMAXLINE1000//元素个数
/*
MAXLINE元素个数
a[]元素数组
R[]指针场
suffix下标
index返回最后的下标序号
values返回最后的下标对应的值
start从第几个开始
K间隔
*/
intfind_n(inta[],intR[],intK,intindex,intvalues,ints=0){
intsuffix;
intfront_node,current_node;
suffix=0;
if(s==0){
current_node=0;
front_node=MAXLINE-1;
}
else{
current_node=s;
front_node=s-1;
}
while(R[front_node]!
=front_node){
printf(%d\n,a[current_node]);
R[front_node]=R[current_node];
if(K==1){
current_node=R[front_node];
continue;
}
for(inti=0;ii++){
front_node=R[front_node];
}
current_node=R[front_node];
}
index=front_node;
values=a[front_node];
return0;
}
intmain(void){
inta[MAXLINE],R[MAXLINE],suffix,index,values,start,i,K;
suffix=index=values=start=0;
K=2;
for(i=0;iMAXLINE;i++){
a[i]=i;
R[i]=i+1;
}
R[i-1]=0;
find_n(a,R,K,index,values,2);
printf(thevalueis%d,%d\n,index,values);
return0;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 高级面试题目 高级 面试 题目