目前本站已有 十几万 份求职资料啦!


SONY精典笔试必读

12-17 15:49:13 来源:http://www.qz26.com 笔试题目   阅读:8646
导读:}printf("\n");}return 0;}2.完成程序,实现对数组的降序排序#includevoid sort( );int main(){int array[]={45,56,76,234,1,34,23,2,3}; //数字任意给出sort( );return 0;}void sort( ){-││││││-}答:使用选择排序法,我为sort函数多加了两个形参,至少第一个是必须的,否则无法传入待排序数组。不知道这样做是否符合题意。void sort(int *array,int num){int temp;for(int i=0;ifor(int j=i+1;jif (array{temp=array;array=array[j];array[j]=temp;}}3.菲波纳契数列,1,1,2,3,5……编写程序求第十项。可以用递归,也可以用其他方法,但要说明你选择的理由。#includeint Pheponatch(int);int main(){
SONY精典笔试必读,标签:银行笔试题目,企业笔试题目,http://www.qz26.com

  }

  printf("\n");

  }

  return 0;

  }

  2.完成程序,实现对数组的降序排序

  #include

  void sort( );

  int main()

  {

  int array[]={45,56,76,234,1,34,23,2,3}; //数字任意给出

  sort( );

  return 0;

  }

  void sort( )

  {

  ---------------------------------------------------------

  ││││││

  ---------------------------------------------------------

  }

  答:使用选择排序法,我为sort函数多加了两个形参,至少第一个是必须的,否则无法传入待排序数组。

  不知道这样做是否符合题意。

  void sort(int *array,int num)

  {

  int temp;

  for(int i=0;ifor(int j=i+1;jif (array{

  temp=array;

  array=array[j];

  array[j]=temp;

  }

  }

  3.菲波纳契数列,1,1,2,3,5……编写程序求第十项。可以用递归,也可以用其他方法,但要说明你

  选择的理由。

  #include

  int Pheponatch(int);

  int main()

  {

www.qz26.com

  printf("The 10th is %d",Pheponatch(10));

  return 0;

  }

  int Pheponatch(int N)

  {

  --------------------------------

  ││││

  --------------------------------

  }

  答:使用递归,理由是递归编程简单,代码容易理解,但缺点是效率不高,而且有深度限制,如果深度太深,

  则堆栈会溢出。

  int Pheponatch(int N)

  {

  if (N==3)

  return 2;

  else if (N==2||N==1)

  return 1;

  else

  return Pheponatch(N-1)+Pheponatch(N-2);

  }

  4.下列程序运行时会崩溃,请找出错误并改正,并且说明原因。

  #include

  #include

  typedef struct TNode

  {

  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, 数字任意给出

  return 0;

  }

  void append(int N)

  {

  TNode* NewNode=(TNode *)malloc(sizeof(TNode));

  NewNode->value=N;

  NewNode->left=NULL; //新增

  NewNode->right=NULL; //新增

  if(root==NULL)

  {

  root=NewNode;

  return;

www.qz26.com

  }

  else

  {

  TNode* temp;

  temp=root;

  while((N>=temp->value && temp->left!=NULL)||(Nvalue && temp->right!=NULL))

  {

  while(N>=temp->value && temp->left!=NULL)

  temp=temp->left;

  while(Nvalue && temp->right!=NULL)

  temp=temp->right;

  }

  if(N>=temp->value)

  temp->left=NewNode;

  else

  temp->right=NewNode;

  return;

  }

  }

  答:因为新节点的左右指针没有赋NULL值,至使下面的while循环不能正确结束而导致内存越界,最后崩

  溃(注意结束条件是temp->left!= NULL或temp->right!=NULL)。改正就是增加两条赋值语句。

上一页  [1] [2] 


Tag:笔试题目银行笔试题目,企业笔试题目求职笔试面试 - 笔试题目
【字号: 】 【打印】 【关闭
最新更新
推荐热门
联系我们 | 网站地图 | 财务资料 | 范文大全 | 求职简历 | 财会考试 | 成功励志
Copyright 二六求职资料网 All Right Reserved.
1 2 3 4 5 6 7 8 9 10