日本一本亚洲最大|日本午夜免费啪视频在|国产自产在线视频一区|亚洲福利精品视频

    <object id="4ihfc"></object>
      
      
    1. <object id="4ihfc"></object>
    2. 我要投稿 投訴建議

      c語言面試編程題

      時間:2023-03-26 13:03:46 面試試題 我要投稿
      • 相關(guān)推薦

      c語言面試編程題

        1、讀文件 file1.txt 的內(nèi)容(例如):

      c語言面試編程題

        12

        34

        56

        輸出到 file2.txt:

        56

        34

        12

        #include

        #include

        int main(void)

        {

        int MAX = 10;

        int *a = (int *)malloc(MAX * sizeof(int));

        int *b;

        FILE *fp1;

        FILE *fp2;

        fp1 = fopen("a.txt","r");

        if(fp1 == NULL)

        {printf("error1");

        exit(-1);

        }

        fp2 = fopen("b.txt","w");

        if(fp2 == NULL)

        {printf("error2");

        exit(-1);

        }

        int i = 0;

        int j = 0;

        while(fscanf(fp1,"%d",&a[i]) != EOF)

        {

        i++;

        j++;

        if(i >= MAX)

        {

        MAX = 2 * MAX;

        b = (int*)realloc(a,MAX * sizeof(int));

        if(b == NULL)

        {

        printf("error3");

        exit(-1);

        }

        a = b;

        }

        }

        for(;--j >= 0;)

        fprintf(fp2,"%d\n",a[j]);

        fclose(fp1);

        fclose(fp2);

        return 0;

        }

        2、寫一段程序,找出數(shù)組中第 k 大小的數(shù),輸出數(shù)所在的位置。例如{2,4,3,4,7}中,第一大的數(shù)是 7,位置在 4。第二大、第三大的數(shù)都是 4,位置在 1、3 隨便輸出哪一個均可。

        函數(shù)接口為:int find_orderk(const int* narry,const int n,const int k)

        要求算法復(fù)雜度不能是 O(n^2)

        可以先用快速排序進(jìn)行排序,其中用另外一個進(jìn)行地址查找代碼如下,在 VC++6.0 運行通過。

        //快速排序

        #include

        usingnamespacestd;

        intPartition (int*L,intlow,int high)

        {

        inttemp = L[low];

        intpt = L[low];

        while (low < high)

        {

        while (low < high && L[high] >= pt)

        --high;

        L[low] = L[high];

        while (low < high && L[low] <= pt)

        ++low;

        L[low] = temp;

        }

        L[low] = temp;

        returnlow;

        }

        voidQSort (int*L,intlow,int high)

        {

        if (low < high)

        {

        intpl = Partition (L,low,high);

        QSort (L,low,pl - 1);

        QSort (L,pl + 1,high);

        }

        }

        intmain ()

        {

        intnarry[100],addr[100];

        intsum = 1,t;

        cout << "Input number:" << endl;

        cin >> t;

        while (t != -1)

        {

        narry[sum] = t;

        addr[sum - 1] = t;

        sum++;

        cin >> t;

        }

        sum -= 1;

        QSort (narry,1,sum);

        for (int i = 1; i <= sum;i++)

        cout << narry[i] << '\t';

        cout << endl;

        intk;

        cout << "Please input place you want:" << endl;

        cin >> k;

        intaa = 1;

        intkk = 0;

        for (;;)

        {

        if (aa == k)

        break;

        if (narry[kk] != narry[kk + 1])

        {

        aa += 1;

        kk++;

        }

        }

        cout << "The NO." << k << "number is:" << narry[sum - kk] << endl;

        cout << "And it's place is:" ;

        for (i = 0;i < sum;i++)

        {

        if (addr[i] == narry[sum - kk])

        cout << i << '\t';

        }

        return0;

        }

      http://krishna123.com/

      【c語言面試編程題】相關(guān)文章:

      c語言編程心得06-19

      c 面試編程問題09-25

      c語言面試基本題09-25

      c語言面試找錯題09-25

      C/C++編程員個人簡歷07-19

      c語言基礎(chǔ)面試題09-25

      c語言面試的常見問題08-05

      C/C++面試試題09-26

      c語言心得04-24