sony笔试题

时间:2023-02-18 08:54:25 面试笔试 我要投稿
  • 相关推荐

sony笔试题

  1. include

sony笔试题

  define n 8

  int main()

  {

  int i;

  int j;

  int k;

  (填写) 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;i

  for(int j=i+1;j

  if (array

  {

  temp=array;

  array=array[j];

  array[j]=temp;

  }

  }

  3.费波那其数列,1,1,2,3,5……编写程序求第十项。可以用递归,也可以用其他方法,但要说明你选择的理由。

  include

  int pheponatch(int);

  int main()

  {

  printf("the 10th is %d",pheponatch(10));

  return 0;

  }

  int pheponatch(int n)

  {

  │ │

  │ │

  }

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

  int pheponatch(int n)

  {

  if (n3)

  return 2;

  else if (n2||n1)

  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(rootnull)

  {

  root=newnode;

  return;

  }

  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)。改正就是增加两条赋值语句,如上文红色部分字体就是新增的两条语句。

【sony笔试题】相关文章:

SONY逻辑笔试题07-31

Sony技术类笔试题及分析08-19

迅雷2011.10.21笔试题08-10

中兴2015笔试题08-02

sony的实习面试经验08-08

海尔04年笔试题及答案07-31

网上找到的sony笔试内容08-10

SONY 培训生一面08-08

交通银行2014笔试题题目分享08-10