sony筆試題

    時間:2024-10-16 18:51:48 面試筆試 我要投稿
    • 相關推薦

    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……編寫程序求第十項?梢杂眠f歸,也可以用其他方法,但要說明你選擇的理由。

      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邏輯筆試題02-18

    sony 邏輯部分筆試題目分享11-21

    SONY 培訓生一面02-23

    SONY 電子類筆試經驗分享11-21

    中國銀行筆試題回顧,新鮮筆經!11-21

    迅雷JAVA廣州站二筆筆試題目分享11-21

    大唐移動測試工程師筆經,筆試題目分享11-21

    網易筆經11-11

    奧美筆經02-23

    91久久大香伊蕉在人线_国产综合色产在线观看_欧美亚洲人成网站在线观看_亚洲第一无码精品立川理惠

      自拍偷精品亚洲手机在线 | 久久久久久国产精选Av香蕉 | 欧美日韩在线视频 | 亚洲一区二区三区自拍天堂 | 最新国内久久免费视频 | 中文字幕福利在线观看 |