c语言面试编程题大纲
来源:范文都 本文已影响3.1W人
来源:范文都 本文已影响3.1W人
1、读文件 的内容(例如):
12
34
56
输出到 :
56
34
12
#include
#include
int main(void)
{
int max = 10;
int *a = (int *)malloc(max * sizeof(int));
int *b;
file *fp1;
file *fp2;
fp1 = fopen("","r");
if(fp1 == null)
{printf("error1");
exit(-1);
}
fp2 = fopen("","w");
if(fp2 == null)
{printf("error2");
exit(-1);
}
int i = 0;
int j = 0;
while(fscanf(fp1,"%d",&a[i]) != eof)
{
i++;
j++;
if(i >= max)
{
max = 2 * max;
b = (int*)realloc(a,max * sizeof(int));
if(b == null)
{
printf("error3");
exit(-1);
}
a = b;
}
}
for(;--j >= 0;)
fprintf(fp2,"%dn",a[j]);
fclose(fp1);
fclose(fp2);
return 0;
}
2、写一段程序,找出数组中第 k 大小的数,输出数所在的位置。例如{2,4,3,4,7}中,第一大的数是 7,位置在 4。第二大、第三大的数都是 4,位置在 1、3 随便输出哪一个均可。
函数接口为:int find_orderk(const int* narry,const int n,const int k)
要求算法复杂度不能是 o(n^2)
可以先用快速排序进行排序,其中用另外一个进行地址查找代码如下,在 vc++6.0 运行通过。
//快速排序
#include
usingnamespacestd;
intpartition (int*l,intlow,int high)
{
inttemp = l[low];
intpt = l[low];
while (low < high)
{
while (low < high && l[high] >= pt)
--high;
l[low] = l[high];
while (low < high && l[low] <= pt)
++low;
l[low] = temp;
}
l[low] = temp;
returnlow;
}
voidqsort (int*l,intlow,int high)
{
if (low < high)
{
intpl = partition (l,low,high);
qsort (l,low,pl - 1);
qsort (l,pl + 1,high);
}
}
intmain ()
{
intnarry[100],addr[100];
intsum = 1,t;
cout << "input number:" << endl;
cin >> t;
while (t != -1)
{
narry[sum] = t;
addr[sum - 1] = t;
sum++;
cin >> t;
}
sum -= 1;
qsort (narry,1,sum);
for (int i = 1; i <= sum;i++)
cout << narry[i] << 't';
cout << endl;
intk;
cout << "please input place you want:" << endl;
cin >> k;
intaa = 1;
intkk = 0;
for (;;)
{
if (aa == k)
break;
if (narry[kk] != narry[kk + 1])
{
aa += 1;
kk++;
}
}
cout << "the no." << k << "number is:" << narry[sum - kk] << endl;
cout << "and it's place is:" ;
for (i = 0;i < sum;i++)
{
if (addr[i] == narry[sum - kk])
cout << i << 't';
}
return0;
}
《C语言程序设计》学习心得体会
C语言程序课程设计心得体会
Oracle数据库面试练习题
硬件工程师面试试题
小编推荐:面试常见问题及回答
求职面试礼仪 言行举止ABC
笔试题目(编程)
C网络游戏程序员笔试题
飞利浦面试题口语面试
网易内推笔试编程题
程序员笔试面试犹如“面试官 + 求职者 = 猫 + 老鼠 ”
C#笔试题CSDN
C/C笔试题目
面试礼仪:言行举止ABC
CEO们最喜爱的13个面试问题
面试时CEO们常问的问题
国家公务员面试问题汇编
C和C经典笔试题及答案
面试礼仪 言行举止ABC
语文试题分类汇编专题仿写
c面试题大纲
面试口语:英文面试常见问题回答
C语言试题大纲
历史编辑笔试题目涉及的方面
Microsoft面试问题
GE笔试C语言部分试题