<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>
            試題

            計算機二級c上機考試題庫

            時間:2025-03-01 08:16:02 試題 我要投稿
            • 相關推薦

            2016計算機二級c上機考試題庫

              一、程序填空題

            2016計算機二級c上機考試題庫

              請補充函數proc(char*str),該函數的功能是把字符串中的內容逆置。

              例如,字符串中原有的字符串為abcdef9,則調用該函數后,串中的內容變為gfedcba。

              注意:部分源程序給出如下。

              請勿改動main()函數和其他函數中的任何內容,僅在函數proc()的橫線上填入所編寫的若干表達式或語句。

              試題程序:

              #include

              #include t

              #include

              #include

              #define M 81

              void proc(char*str)

              【2】 ;

              【3】 ;

              }

              }

              void main()

              {

              char str[M];

              system("CLS"):

              printf("Enter a string:");

              gets(str);

              printf("The original string is:");

              puts(str);

              proc(str);

              printf("\n");

              printf("The string after modified:");

              puts(str);

              }

              二、程序改錯題

              下列給定程序中,函數proc()的功能是:將字符串str 中所有字符復制到字符串b中,要求每復制3個字符之后插入一個空格。例如,在調用proc()函數之前給字符串str 輸入abcdefghijk,調用函數之后,字符串b中的內容則為abe def ghijk。

              請修改程序中的錯誤,使它能得出正確的結果。

              注意:不要改動main()函數,不得增行或刪行,也不得更改程序的結構。

              試題程序:

              #include

              void proc(char*str,char*b)

              {

              int i,k=0:

              while(*str)

              //****found****

              {

              i=1;

              //****found****

              while(i<3||*str)

              {

              b[k]=*str;

              k++;str++;i++;

              }

              if(*str)

              //****found****

              {b[k]=’’;}

              void main()

              {

              char str[80],b[80];

              printf("Enter a string:");gets(str);

              printf("The original string:");

              puts(str);

              proc(str,b);

              printf("\nThe string after insert

              space:");puts(b);printf("\n\n");

              }

              三、程序設計題

              請編寫函數proc(),該函數的功能是:移動一維數組中的內容,若數組中有n個整數,要求把下標從P到n-1(p≤n-1)的數組元素平移到數組的前面。

              例如,一維數組中的原始內容為1,2,3,4,5,6,7,8,9,10,11,12,13,14,p的值為4。移動后,一維數組中的內容應為5,6,7,8,9,10,11,12,13,14,1,2,3,4。

              注意:部分源程序給出如下。

              請勿改動main()函數和其他函數中的任何內容,僅在函數proc()的花括號中填入所編寫的若干語句。

              試題程序:

              #include

              #define M 80

              void proc(int * w,int P,int n)

              {

              }

              void main()

              {

              int arr[M]={1,2,3,4,5,6,7,8,9,10,11,12,13,14};

              int i,p,n=14;

              printf("The original data:\n");

              for(i=0:i

              printf("%3d",arr[i]);

              printf("\n\nEnter P:");

              scanf("%d",&p);

              proc(arr,p,n);

              printf("\nThe data after moving:\n");

              for(i=0:i

              printf("%3d",arr[i]);

              printf("\n\n");

              }

              【參考答案】

              一、程序填空題

              【1】i

              【解析】要將字符串中的內容逆置.可以通過將字符串中的第一個字符和最后一個字符互換,第二個和倒數第二個互換,直到字符串str最中間的字符為止,因此,【1】處填“i

              二、程序改錯題

              (1)錯誤:i=1:

              正確:i=0;

              (2)錯誤:while(i<3||*str)

              正確:while(i<3&&*str)

              (3)錯誤:b[k]=’’;

              正確:b[k++]=’’;

              【解析】由函數proc()可知,變量i為計算每次字符個數是否到3的計數器變量,其初始值為0,因此,i=1;應改為i =0;。當計數器i小于3,而且字符串str沒有結束時,將str 中的字符賦值給字符串b,因此,“while(i<3||*str)”應改為“while(i<3&&*str)”。每次計數器變量為3而字符串str沒有結束時,為字符串b賦值為空格,而不是空字符,因此,“b[k]=’’;”應改為“b[k++]=’’;”。

              三、程序設計題

              void proc(int*w,int p,int n)

              {

              int i,j,t;

              for(i=P;i<=n-1;i++)

              { t=w[n-1];//t放最后一個元素

              for(j=n-2;j>=0;j--)

              w[j+1]=w[j]; //每循環一次,把所有的元

              素往后侈

              w[0]=t; //再把最后一個放到第一個空間中

              }

              }

              【解析】題目中要求把下標從p到n-1的數組元素平移到數組的前面,可以通過每一次循環將最后一個元素放在第一個位置上,使其成為第一個元素,其余元素后移一個位置。通過n-1-p次循環實現將從p到n-1的數組元素平移到數組的前面。

            【計算機二級c上機考試題庫】相關文章:

            2015計算機二級c語言上機題庫06-19

            全國計算機等級考試二級c語言上機題庫10-28

            2024二級c語言上機題庫04-18

            2017計算機二級C語言上機題庫及答案08-07

            2016年計算機二級C語言上機題庫11-07

            計算機二級考試《C語言》上機答題技巧06-27

            2015全國計算機二級c語言上機題庫(附答案)09-29

            計算機二級考試C++上機考試試題05-22

            計算機二級考試C上機考試試題及答案10-29

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看