A、该题用语言描述是指:第i行第一个输出*,然后输出i-1个.,重复上i次。 #include
#define N 8
int main()
{
int i;
int j;
int k;
for(i=0;i<=N;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
for(k=1;k
printf(".");
}
printf("n");
}
return 0;
B、降序排列数组,很常见的,这里我采用冒泡排序法还有选择排序法:
冒泡排序:
#include
void sort(int *array,int num );
int main()
{
int num=9,i;
int array[]={45,56,76,234,1,34,23,2,3};
sort(array,num);
for(i=0;i
printf("%dt",array);
return 0;
}
void sort(int *array,int num)
{
int i,j;
int temp;
for(i=0;i
{
for(j=0;j
{
if(array[j]
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
}
选择排序:
#include
void sort(int *array,int num );
int main()
{
int num=9,i;
int array[]={45,56,76,234,1,34,23,2,3};
sort(array,num);
for(i=0;i
printf("%dt",array);
return 0;
}
void sort(int *array,int num)
{
int i,j,k;
int temp;
for(i=0;i
{
k=i; //每次一趟结束后就从新的一个值开始,无需从头来,因为每一次排完后都是最大的了
for(j=i+1;j
if(array[k]
{
k=j;
}
if(k!=i) //如果k不等于i就说明有更大的值,交换二值
{
temp=array;
array=array[k];
array[k]=temp;
}
}
}
C、该题考查同学们对递归算法的认识程度,在这里我们采用迭代算法,优点是程序运行效率高,而且不用担心堆栈溢出,在运算值大的情况下比递归算法可以提高上万倍的速度,比如同样计算30,递归算法用时
0.019s,而迭代算法则只用了0.003s,可见是递归算法的八分之一,值更大时这种越明显。缺点是程序比较不容易懂。有兴趣的可以参见《C和指针》127页,具体程序如下:
递归法:
#include
int Pheponatch(int);
int main()
{
printf("The 10th is %d",Pheponatch(30));
return 0;
}
int Pheponatch(int N)
{
if(N<=2)
return 1;
return Pheponatch(N-1)+Pheponatch(N-2);
}
迭代法:
#include
int Pheponatch(int);
int main()
{
printf("The 10th is %d",Pheponatch(30));
return 0;
}
int Pheponatch(int n)
{
long result;
long previous_result;
long next_older_result;
result=previous_result=1;
while(n>2)
{
n-=1;
next_older_result=previous_result+result; previous_result=result;
result=next_older_result;
}
return result;
}
D、源程序如下,红笔写出的是修改的地方:(其实这个程序有好多漏洞,不知为什么会那这个程序来考)
#include
#include
typedef struct{
TNode* left;
TNode* right;
int value;
} TNode;
TNode* root=NULL;
void append(int N);
int main()
{
append(63);
append(45);
append(32);
append(77);
append(96);
append(21);
append(17); // Again, 数字任意给出
}
void append(int N)
{
TNode* NewNode=(TNode *)malloc(sizeof(TNode));
NewNode->value=N;
NewNode->right=NULL;
NewNode->left=NULL;
if(root==NULL)
{
root=NewNode;
return;
}
else
{
TNode* temp;
temp=root;
while((N>=e && !=NULL) || (N
right
!=NULL
))
{
while(N>=e && !=NULL)
temp=;
while(N
temp=t;
}
if(N>=e)
=NewNode;
else
t=NewNode;
return;
}
}
原因:因为新节点的左右指针没有赋 NULL 值,至使下面的 while循环不能正确结束而导致内
存越界,最后崩溃(注意结束条件是 temp->left!= NULL 或 temp->right!=NULL)。
sony往年程序笔试真题
才干屋
人气:3.02W
猜你喜欢
- 1索尼sony东京笔试(上海交通大学)
- 2索尼SONY笔经
- 3小议sybase笔试题
- 4索尼SONY笔经(复旦大学)
- 5豪威(Omnivision)笔试题目(2005)
- 6Sybase笔试题型
- 7SC Johnson的Open Question
- 8凹凸电子笔试题目(Linux Software Engineer)
- 9英语面试问题: What Interests You About This Job?
- 10Questions to Ask(笔试)
- 11英语演讲稿IS MONEY EVERYTHING
- 12Beyondsoft职位面试6篇
- 13英语演讲稿-How to say future?
- 14麦肯锡(McKinsey)笔试题目小结
- 15网友:德勤consulting笔试过程
今日热门
- 1写给高考的考生:坚定信心,Everyone is No.
- 2程序设计基础试题
- 3SONY程序题
- 4攒rp--yahoo非技术笔试题B卷
- 5欧莱雅笔试题case study
- 6Be Your Best and Market Yourself 找工之旅
- 72018年五模考试工作程序
- 8大学生英语演讲稿There is only one failure called never try
- 9Merrill Lynch(美林)的Open Question
- 10yahoo在线笔试题(c语言)
- 11英语励志文章:You Have Only One Life
- 12Intel笔试真题技术笔试题型
- 13Suningin详解面试笔试题--中兴面试题目
- 14赛门铁克(Symantec)笔试题目(回忆篇)
- 15Symantec笔试
- 16Suningin详解面试笔试题
- 17面试问题:Why should we hire you
- 18思纬(Synovate)面试小结