• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. C語言筆試題

        時間:2023-04-05 04:20:24 筆試題目 我要投稿
        • 相關推薦

        C語言筆試題集錦

          1、編寫一個 C 函數,該函數在一個字符串中找到可能的最長的子字符串,且該字符串是由同一字符組成的。

        C語言筆試題集錦

          char * search(char *cpSource, char ch)

          {

          char *cpTemp=NULL, *cpDest=NULL;

          int iTemp, iCount=0;

          while(*cpSource)

          {

          if(*cpSource == ch)

          {

          iTemp = 0;

          cpTemp = cpSource;

          while(*cpSource == ch)

          ++iTemp, ++cpSource;

          if(iTemp > iCount)

          iCount = iTemp, cpDest = cpTemp;

          if(!*cpSource)

          break;

          }

          ++cpSource;

          }

          return cpDest;

          }

          2、請編寫一個 C 函數,該函數在給定的內存區域搜索給定的字符,并返回該字符所在位置索引值。

          int search(char *cpSource, int n, char ch)

          {

          int i;

          for(i=0; i return i;

          }

          一個單向鏈表,不知道頭節點,一個指針指向其中的一個節點,問如何刪除這個指針指向的節點?

          將這個指針指向的next節點值copy到本節點,將next指向next->next,并隨后刪除原next指向的節點。

          #include

          void foo(int m, int n)

          {

          printf(“m=%d, n=%d\n”, m, n);

          }

          int main()

          {

          int b = 3;

          foo(b+=3, ++b);

          printf(“b=%d\n”, b);

          return 0;

          }

          輸出:m=7,n=4,b=7(VC6.0)

          這種方式和編譯器中得函數調用關系相關即先后入棧順序。不過不同

          編譯器得處理不同。也是因為C標準中對這種方式說明為未定義,所以

          各個編譯器廠商都有自己得理解,所以最后產生得結果完全不同。

          因為這樣,所以遇見這種函數,我們首先要考慮我們得編譯器會如何處理

          這樣得函數,其次看函數得調用方式,不同得調用方式,可能產生不同得

          結果。最后是看編譯器優化。

          2.寫一函數,實現刪除字符串str1中含有的字符串str2.

          第二個就是利用一個KMP匹配算法找到str2然后刪除(用鏈表實現的話,便捷于數組)

          /*雅虎筆試題(字符串操作)

          給定字符串A和B,輸出A和B中的最大公共子串。

          比如A=”aocdfe” B=”pmcdfa” 則輸出”cdf”

          */

          //Author: azhen

          #include

          #include

          #include

          char *commanstring(char shortstring[], char longstring[])

          {

          int i, j;

          char *substring=malloc(256);

          if(strstr(longstring, shortstring)!=NULL) //如果……,那么返回shortstring

          return shortstring;

          for(i=strlen(shortstring)-1;i>0; i–) //否則,開始循環計算

          {

          for(j=0; j<=strlen(shortstring)-i; j++){

          memcpy(substring, &shortstring[j], i);

          substring[i]='\0';

          if(strstr(longstring, substring)!=NULL)

          return substring;

          }

          }

          return NULL;

          }

          main()

          {

          char *str1=malloc(256);

          char *str2=malloc(256);

          char *comman=NULL;

          gets(str1);

          gets(str2);

          if(strlen(str1)>strlen(str2)) //將短的字符串放前面

          comman=commanstring(str2, str1);

          else

          comman=commanstring(str1, str2);

          printf(“the longest comman string is: %s\n”, comman);

          }

          11.寫一個函數比較兩個字符串str1和str2的大小,若相等返回0,若str1大于

          str2返回1,若str1小于str2返回-1

          int strcmp ( const char * src,const char * dst)

          {

          int ret = 0 ;

          while( ! (ret = *(unsigned char *)src – *(unsigned char *)dst) && *dst)

          {

          ++src;

          ++dst;

          }

          if ( ret < 0 )

          ret = -1 ;

          else if ( ret > 0 )

          ret = 1 ;

          return( ret );

          }

          3,求1000!的未尾有幾個0(用素數相乘的方法來做,如72=2*2*2*3*3);

          求出1->1000里,能被5整除的數的個數n1,能被25整除的數的個數n2,能被125整除的數的個數n3,

          能被625整除的數的個數n4.

          1000!末尾的零的個數=n1+n2+n3+n4;

          #include

          #define NUM 1000

          int find5(int num){

          int ret=0;

          while(num%5==0){

          num/=5;

          ret++;

          }

          return ret;

          }

          int main(){

          int result=0;

          int i;

          for(i=5;i<=NUM;i+=5)

          {

          result+=find5(i);

          }

          printf(” the total zero number is %d\n”,result);

          return 0;

          }

        《&.doc》
        将本文的Word文档下载到电脑,方便收藏和打印
        推荐度:
        点击下载文档

        【C語言筆試題】相關文章:

        華為筆試題(C語言)12-10

        華為C語言筆試題12-12

        基礎C++/C語言筆試題分享11-21

        yahoo在線筆試題(c語言)12-12

        C語言筆試試題及答案07-31

        c語言筆試題目及答案08-17

        2015C語言筆試題及答案08-08

        計算機C語言試題及答案02-25

        華為筆試題及分析目(C語言篇)11-06

        2017年c語言面試筆試題11-22

        在线咨询
        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 亚洲区自拍偷拍视频 | 午夜成午夜成年片在线观看bd | 日韩国产欧美一二三区 | 亚洲综合久久综合网 | 亚洲国产制服丝袜清纯 | 久久久理论片免费观看 |

            C語言筆試題集錦

              1、編寫一個 C 函數,該函數在一個字符串中找到可能的最長的子字符串,且該字符串是由同一字符組成的。

            C語言筆試題集錦

              char * search(char *cpSource, char ch)

              {

              char *cpTemp=NULL, *cpDest=NULL;

              int iTemp, iCount=0;

              while(*cpSource)

              {

              if(*cpSource == ch)

              {

              iTemp = 0;

              cpTemp = cpSource;

              while(*cpSource == ch)

              ++iTemp, ++cpSource;

              if(iTemp > iCount)

              iCount = iTemp, cpDest = cpTemp;

              if(!*cpSource)

              break;

              }

              ++cpSource;

              }

              return cpDest;

              }

              2、請編寫一個 C 函數,該函數在給定的內存區域搜索給定的字符,并返回該字符所在位置索引值。

              int search(char *cpSource, int n, char ch)

              {

              int i;

              for(i=0; i return i;

              }

              一個單向鏈表,不知道頭節點,一個指針指向其中的一個節點,問如何刪除這個指針指向的節點?

              將這個指針指向的next節點值copy到本節點,將next指向next->next,并隨后刪除原next指向的節點。

              #include

              void foo(int m, int n)

              {

              printf(“m=%d, n=%d\n”, m, n);

              }

              int main()

              {

              int b = 3;

              foo(b+=3, ++b);

              printf(“b=%d\n”, b);

              return 0;

              }

              輸出:m=7,n=4,b=7(VC6.0)

              這種方式和編譯器中得函數調用關系相關即先后入棧順序。不過不同

              編譯器得處理不同。也是因為C標準中對這種方式說明為未定義,所以

              各個編譯器廠商都有自己得理解,所以最后產生得結果完全不同。

              因為這樣,所以遇見這種函數,我們首先要考慮我們得編譯器會如何處理

              這樣得函數,其次看函數得調用方式,不同得調用方式,可能產生不同得

              結果。最后是看編譯器優化。

              2.寫一函數,實現刪除字符串str1中含有的字符串str2.

              第二個就是利用一個KMP匹配算法找到str2然后刪除(用鏈表實現的話,便捷于數組)

              /*雅虎筆試題(字符串操作)

              給定字符串A和B,輸出A和B中的最大公共子串。

              比如A=”aocdfe” B=”pmcdfa” 則輸出”cdf”

              */

              //Author: azhen

              #include

              #include

              #include

              char *commanstring(char shortstring[], char longstring[])

              {

              int i, j;

              char *substring=malloc(256);

              if(strstr(longstring, shortstring)!=NULL) //如果……,那么返回shortstring

              return shortstring;

              for(i=strlen(shortstring)-1;i>0; i–) //否則,開始循環計算

              {

              for(j=0; j<=strlen(shortstring)-i; j++){

              memcpy(substring, &shortstring[j], i);

              substring[i]='\0';

              if(strstr(longstring, substring)!=NULL)

              return substring;

              }

              }

              return NULL;

              }

              main()

              {

              char *str1=malloc(256);

              char *str2=malloc(256);

              char *comman=NULL;

              gets(str1);

              gets(str2);

              if(strlen(str1)>strlen(str2)) //將短的字符串放前面

              comman=commanstring(str2, str1);

              else

              comman=commanstring(str1, str2);

              printf(“the longest comman string is: %s\n”, comman);

              }

              11.寫一個函數比較兩個字符串str1和str2的大小,若相等返回0,若str1大于

              str2返回1,若str1小于str2返回-1

              int strcmp ( const char * src,const char * dst)

              {

              int ret = 0 ;

              while( ! (ret = *(unsigned char *)src – *(unsigned char *)dst) && *dst)

              {

              ++src;

              ++dst;

              }

              if ( ret < 0 )

              ret = -1 ;

              else if ( ret > 0 )

              ret = 1 ;

              return( ret );

              }

              3,求1000!的未尾有幾個0(用素數相乘的方法來做,如72=2*2*2*3*3);

              求出1->1000里,能被5整除的數的個數n1,能被25整除的數的個數n2,能被125整除的數的個數n3,

              能被625整除的數的個數n4.

              1000!末尾的零的個數=n1+n2+n3+n4;

              #include

              #define NUM 1000

              int find5(int num){

              int ret=0;

              while(num%5==0){

              num/=5;

              ret++;

              }

              return ret;

              }

              int main(){

              int result=0;

              int i;

              for(i=5;i<=NUM;i+=5)

              {

              result+=find5(i);

              }

              printf(” the total zero number is %d\n”,result);

              return 0;

              }