第81套

1.程序填空题

给定程序中,函数fun的功能是:将不带头结点的单向链表结点数据域中的数据从小到大排序。即若原链表从头至尾结点数据域依次为:10、4、2、8、6,排序后,从头至尾结点数据域依次为:2、4、6、8、10。

请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。

注意:不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
#define  N  6
typedef struct node 
{
    int  data;
    struct node  *next;
} NODE;
void fun(NODE  *h)
{ 
    NODE  *p, *q;    
    int  t;
    p = h;
    while (p) 
    {
    /**********found**********/
       q = __1__ ;
    /**********found**********/
       while (__2__)
       {  
           if (p->data > q->data)
           { t=p->data; p->data=q->data; q->data=t; }
           q = q->next;
       }
    /**********found**********/
       p = __3__ ;
    }
}
NODE *creatlist(int  a[])
{  
    NODE  *h,*p,*q;        
    int  i;
    h=NULL;
    for(i=0; i<N; i++)
    {  
        q=(NODE *)malloc(sizeof(NODE));
        q->data=a[i];
        q->next = NULL;
        if (h == NULL)  h = p = q;
        else    {  p->next = q;  p = q;   }
    }
    return  h;
}
void outlist(NODE  *h)
{  
    NODE  *p;
    p=h;
    if (p==NULL)  printf("The list is NULL!\n");
    else
    {  
        printf("\nHead  ");
        do { 
           printf("->%d", p->data); 
           p=p->next;  
        } while(p!=NULL);
        printf("->End\n");
    }
}
int main()
{  
    NODE  *head;
    int  a[N]= {0, 10, 4, 2, 8, 6 };
    head=creatlist(a);
    printf("\nThe original list:\n");
    outlist(head);
    fun(head);
    printf("\nThe list after inverting :\n");
    outlist(head);
    return 0;
}

2.程序修改题

给定程序中,函数fun的功能是:判断字符ch是否与字符串str中的某个字符相同,若相同,什么也不做;若不同,则插在串的最后。

请改正函数fun中指定部位的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

#include   <stdio.h>
#include   <string.h>
/**********found**********/
void fun(char str, char ch )
{   
    while (*str && *str != ch) str++;
    /**********found**********/
    if (*str == ch)
    {  
        str [ 0 ] = ch;
    /**********found**********/
        str[1] = '0';
    }
}
int main()
{    
    char  s[81],  c ;
    printf( "\nPlease enter a string:\n" );  
    gets ( s );
    printf("\n Please enter the character to search : ");
    c = getchar();
    fun(s, c) ;
    printf( "\nThe result  is %s\n",  s);
    return 0;
}

3.程序设计题

编写函数fun,它的功能是:把字符串中的内容逆置。

例如,字符串中原有的内容为:abcdefg,则调用该函数后,串中的内容为:gfedcba。

注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <string.h>
#include <stdio.h>
#define   N   81
void NONO(void);
void fun(char *s)
{
}
int main()
{
    char a[N];
    printf("Enter a string: ");gets(a);
    printf("The original string is:  ");puts(a);
    fun(a);
    printf("\n");
    printf("The string after modified:  ");
    puts(a);
    NONO( );
    return 0;
}
void NONO(void)
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */
    int i ;
    char a[N] ;
    FILE *rf, *wf ;
    rf = fopen("in.dat", "r") ;
    wf = fopen("out.dat", "w") ;
    for(i = 0 ; i < 9 ; i++)
    {
       fscanf(rf, "%s", a) ;
       fun(a) ;
       fprintf(wf, "%s\n", a) ;
    }
    fclose(rf) ;
    fclose(wf) ;
}
计算机等级考试二级C语言上机题集(第81~85套)计算机等级考试二级C语言上机题集(第81~85套)

1.(1)p->next   (2)q   (3)p->next
2void fun(char *str, char ch )
    if (*str != ch)
    str[1] = '\0';
3void fun(char *s)
    {
          int i,j;
          char t;
          for (i=0,j=strlen(s)-1;i<j;i++,j--)
          {
               t=s[i]; s[i]=s[j]; s[j]=t;
          }
    }

第81套参考答案

第82套

1.程序填空题

给定程序中,函数fun的功能是:在形参ss所指字符串数组中,将所有串长超过k的字符串中右边的字符删除,只保留左边的k个字符。ss所指字符串数组中共有N个字符串,且串长<M。

请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。

注意:不得增行或删行,也不得更改程序的结构!

#include  <stdio.h>
#include  <string.h>
#define   N   5
#define   M   10
/**********found**********/
void fun(char  (*ss) __1__, int  k)
{ 
    int  i=0  ;
    /**********found**********/
    while(i< __2__) 
    {
    /**********found**********/
       ss[i][k]=__3__;  i++;  
    }
}
int main()
{ 
    char  x[N][M]={"Create","Modify","Sort",
                   "skip","Delete"};
    int  i;
    printf("\nThe original string\n\n");
    for(i=0;i<N;i++) puts(x[i]);  
    printf("\n");
    fun(x,4);
    printf("\nThe string after deleted :\n");
    for(i=0; i<N; i++)  puts(x[i]);  
    printf("\n");
    return 0;
}

2.程序修改题

给定程序中,函数fun的功能是:先从键盘输入一个3行3列矩阵的各个元素的值,然后输出主对角线元素之和。

请改正函数fun中指定部位的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

#include <stdio.h>
void fun()
{
   /*********found**********/
   int a[3][3],sum;
   int i,j;
   for (i=0;i<3;i++)
   {  
       for (j=0;j<3;j++)
   /*********found**********/
         scanf("%d",a[i][j]);
   }
   for (i=0;i<3;i++)
     sum=sum+a[i][i];
   printf("Sum=%d\n",sum);
}
int main()
{
   fun();
   return 0;
}

3.程序设计题

编写函数fun,它的功能是:实现矩阵(3行3列)的转置(即行列互换)

例如,输入下面的矩阵

100 200 300

400 500 600

700 800 900

程序输出

100 400 700

200 500 800

300 600 900

注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <stdio.h>
void NONO(void);
void fun(int array[3][3])
{
}
int main()
{
   int i,j;
   int array[3][3]={{100,200,300},
                   {400,500,600},
                   {700,800,900}};
   for (i=0;i<3;i++)
   {
       for (j=0;j<3;j++)
         printf("%7d",array[i][j]);
       printf("\n");
   }
   fun(array);
   printf("Converted array:\n");
   for (i=0;i<3;i++)
   {
       for (j=0;j<3;j++)
         printf("%7d",array[i][j]);
       printf("\n");
   }
   NONO();
   return 0;
}
void NONO(void)
{
/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */
   int i,j, array[3][3];
   FILE *rf, *wf ;
   rf = fopen("in.dat","r") ;
   wf = fopen("out.dat","w") ;
   for (i=0;i<3;i++)
     for (j=0;j<3;j++)
       fscanf(rf, "%d", &array[i][j]);
   fun(array);
   for (i=0;i<3;i++)
   {
       for (j=0;j<3;j++)
          fprintf(wf, "%7d", array[i][j]);
       fprintf(wf, "\n");
   }
   fclose(rf) ;
   fclose(wf) ;
}
计算机等级考试二级C语言上机题集(第81~85套)计算机等级考试二级C语言上机题集(第81~85套)

1.(1)[M]   (2)N   (3'\0'
2int a[3][3],sum=0;
    scanf("%d",&a[i][j]);
3void fun(int array[3][3])
    {
          int i,j,t;
          for (i=1;i<3;i++)
             for (j=0;j<i;j++)
            {
                 t=array[i][j];
                 array[i][j]=array[j][i];
                 array[j][i]=t;
            }
    }

第82套参考答案

第83套

1.程序填空题

给定程序中,函数fun的功能是:找出形参s所指字符串中出现频度最高的字母(不区分大小写),并统计其出现的次数。

例如,形参s所指字符串为:abcAbsmaxless,程序执行后的输出结果为:

letter ‘a’:3 times

letter ‘s’:3 times

请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。

注意:不得增行或删行,也不得更改程序的结构!

#include  <stdio.h>
#include  <string.h>
#include  <ctype.h>
void fun(char  *s)
{ 
    int  k[26]={0},n,i,max=0;    
    char  ch;
    while(*s)
    { 
        if( isalpha(*s) ) 
        {
    /**********found**********/
           ch=tolower(__1__);
           n=ch-'a';
    /**********found**********/
           k[n]+= __2__ ;
        }
        s++;
    /**********found**********/
        if(max<k[n]) max= __3__ ;
    }
    printf("\nAfter count :\n");
    for(i=0; i<26;i++)
      if (k[i]==max) 
        printf("\nletter \'%c\': %d times\n",i+'a',k[i]);
}
int main()
{ 
    char  s[81];
    printf("\nEnter a string:\n\n");  
    gets(s);
    fun(s);
    return 0;
}

2.程序修改题

给定程序中,函数fun的功能是:将长整型数中每一位上为奇数的数依次取出,构成一个新数放在t中。高位仍在高位,低位仍在低位。

例如,当s中的数为:87653142时,t中的数为:7531。

请改正函数fun中指定部位的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

#include <conio.h>
#include <stdio.h>
void fun (long  s, long *t)
{ 
    int   d;
    long  sl=1;
    /************found************/
    t = 0;
    while ( s > 0)
    {  
        d = s%10;
    /************found************/
        if (d%2 == 0)
        {  
            *t = d * sl + *t;
            sl *= 10;
        }
        s /= 10;
    }
}
int main()
{  
    long s, t;
    printf("\nPlease enter s:"); 
    scanf("%ld", &s);
    fun(s, &t);
    printf("The result is: %ld\n", t);
    return 0;
}

3.程序设计题

编写函数fun,它的功能是:计算并输出给定数组(长度为9)中每相邻两个元素之平均值的平方根之和。

例如,给定数组中的9个元素依次为12.0、34.0、4.0、23.0、34.0、45.0、18.0、3.0、11.0,输出应为:s=35.951014。

注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <stdio.h>
#include <math.h>
void NONO(void);
double fun(double  x[9])
{
}
int main()
{
    double  s,a[9]={12.0,34.0,4.0,23.0,34.0,45.0,18.0,3.0,11.0};
    int  i;
    printf("\nThe original data is :\n");
    for(i=0;i<9;i++) printf("%6.1f",a[i]);
    printf("\n\n");
    s=fun(a);
    printf("s=%f\n\n",s);
    NONO();
    return 0;
}
void NONO(void)
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */
    FILE *rf, *wf ; int i, j ;
    double s, a[9] ;
    rf = fopen("in.dat", "r") ;
    wf = fopen("out.dat", "w") ;
    for(i = 0 ; i < 5 ; i++)
    {
       for(j = 0 ; j < 9 ; j++)
          fscanf(rf, "%lf", &a[j]) ;
       s = fun(a) ;
       fprintf(wf, "%lf\n", s) ;
    }
    fclose(rf) ;
    fclose(wf) ;
}
计算机等级考试二级C语言上机题集(第81~85套)计算机等级考试二级C语言上机题集(第81~85套)

1.(1)*s   (213)k[n]
2. *t = 0;
    if (d%2 != 0)
3double fun(double  x[9])
    {
         double s=0.0;
         int i;
         for (i=0;i<9-1;i++)
             s+=sqrt(fabs((x[i]+x[i+1])/2));
         return s;
    }

第83套参考答案

第84套

1.程序填空题

给定程序中,函数fun的功能是:计算下列多项式的值

计算机等级考试二级C语言上机题集(第81~85套)

例如,当n=10时,输出结果为:9.612558。

请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。

注意:不得增行或删行,也不得更改程序的结构!

#include  <stdio.h>
double fun(int  n)
{ 
    int  i;    
    double  s, t;
    /**********found**********/
    s=__1__;
    /**********found**********/
    for(i=1; i<=__2__; i++)
    { 
        t=2.0*i;
    /**********found**********/
        s=s+(2.0*i-1)*(2.0*i+1)/__3__;
    }
    return  s;
}
int main()
{ 
    int  n=-1;
    while(n<0)
    { 
        printf("Please input(n>0): "); 
        scanf("%d",&n);  
    }
    printf("\nThe result is: %f\n",fun(n));
    return 0;
}

2.程序修改题

给定程序中,函数fun的功能是:统计子字符串substr在字符串str中出现的次数。

例如,若字符串为aaaslkaaas,子字符串为as,则应输出2。

请改正函数fun中指定部位的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

#include <stdio.h>
int fun (char *str,char *substr)
{  
  int i,j,k,num=0;
  /************found************/
  for(i = 0, str[i], i++)
    for(j=i,k=0;substr[k]==str[j];k++,j++)
  /************found************/
      If(substr[k+1]=='\0')
      {  
          num++;
          break;
      }
  return num;
}
int main()
{
  char str[80],substr[80];
  printf("Input a string:") ;
  gets(str);
  printf("Input a substring:") ;
  gets(substr);
  printf("%d\n",fun(str,substr));
  return 0;
}

3.程序设计题

编写函数fun,它的功能是:根据下列公式求π值(要求满足精度eps,即某项小于eps时停止迭代)。

计算机等级考试二级C语言上机题集(第81~85套)

例如,给定精度eps为0.0005时,应当输出PI=3.140578。

注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <stdio.h>
#include <math.h>
void NONO(void);
double  fun ( double  eps)
{
}
int main()
{
    double  x;
    printf("Input eps:") ;
    scanf("%lf",&x);
    printf("\neps = %f, PI=%f\n", x, fun(x));
    NONO();
    return 0;
}
void NONO(void)
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
    FILE *fp, *wf ;
    int i ;
    double x ;
    fp = fopen("in.dat","r") ;
    wf = fopen("out.dat","w") ;
    for(i = 0 ; i < 10 ; i++)
    {
      fscanf(fp, "%lf", &x) ;
      fprintf(wf, "%f\n", fun(x)) ;
    }
    fclose(fp) ;
    fclose(wf) ;
}
计算机等级考试二级C语言上机题集(第81~85套)计算机等级考试二级C语言上机题集(第81~85套)

1.(102)n   (3)(t*t)
2for(i = 0; str[i]; i++)
    if(substr[k+1]=='\0')
3double  fun ( double  eps)
    {
          double  s,t;
          int  n=1;
          s=0.0;
          t=1.0;
          while( t>eps)
          {
              s+=t;
              t=t * n/(2*n+1);
              n++;
          }
          return (2*s);
    }

第84套参考答案

第85套

1.程序填空题

给定程序中,通过定义学生结构体数组,存储了若干名学生的学号、姓名和3门课的成绩。函数fun的功能是:将存放学生数据的结构体数组,按照姓名的字典序(从小到大)排序。

请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。

注意:不得增行或删行,也不得更改程序的结构!

#include  <stdio.h>
#include  <string.h>
struct student 
{
    long  sno;
    char  name[10];
    float  score[3];
};
void fun(struct student  a[], int  n)
{
    /**********found**********/
    __1__ t;
    int  i, j;
    /**********found**********/
    for (i=0; i<__2__; i++)
       for (j=i+1; j<n; j++)
    /**********found**********/
         if (strcmp(__3__) > 0)
         { t=a[i];  a[i]=a[j]; a[j]=t; }
}
int main()
{ 
    struct student s[4]={{10001,"ZhangSan",95,80,88},
                    {10002,"LiSi", 85, 70, 78},
                    {10003,"CaoKai", 75, 60, 88}, 
                    {10004,"FangFang", 90, 82, 87}};
    int  i, j;
    printf("\n\nThe original data :\n\n");
    for (j=0; j<4; j++)
    {  
        printf("\nNo: %ld  Name: %-8s      Scores:  ",s[j].sno, s[j].name);
        for (i=0; i<3; i++)  
            printf("%6.2f ", s[j].score[i]);
        printf("\n");
    }
    fun(s, 4);
    printf("\n\nThe data after sorting :\n\n");
    for (j=0; j<4; j++)
    {  
        printf("\nNo: %ld  Name: %-8s      Scores:  ",s[j].sno, s[j].name);
        for (i=0; i<3; i++)  
            printf("%6.2f ", s[j].score[i]);
        printf("\n");
    }
    return 0;
}

2.程序修改题

给定程序中,函数fun的功能是:计算n的5次方的值(规定n的值大于2,小于8),通过形参指针传回主函数。并计算该值的低3位数字之和作为函数值返回。

例如,7的5次方是16807,其低3位数字的和值是15。

请改正函数fun中指定部位的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

#include <stdio.h>
#include <math.h>
int  fun(int  n ,int  *value)
{  
    int  d,s,i;
    /**************found**************/
    d=0;  s=1;
    for(i=1; i<=5; i++)  d=d*n;
    *value=d;
    for(i=1; i<=3; i++)
    {  
        s=s+d%10;
    /**************found**************/
        s=s/10;
    }
    return  s;
}
int main()
{  
    int  n, sum, v;
    do {
       printf("\nEnter n( 2<n<8):  ");
       scanf("%d",&n);  
    } while(n<=2||n>=8);
    sum=fun( n,&v );
    printf("\nThe result:\n value=%d  sum=%d\n",v,sum);
    return 0;
}

3.程序设计题

编写函数fun,它的功能是:计算当x<0.97时下列多项式的值,直到|S(n)-S(n-1)|<0.00001为止。

计算机等级考试二级C语言上机题集(第81~85套)

例如,在主函数中从键盘给x输入0.21后,输出为:S=1.100000。

注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <stdio.h>
#include <math.h>
void NONO(void);
double fun(double  x)
{
}
int  main()
{
    double  x,s;
    printf("Input x:  ");
    scanf("%lf",&x);
    s=fun(x);
    printf("s=%f\n",s);
    NONO();
    return 0;
}
void NONO(void)
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */
    FILE *rf, *wf ; int i ;
    double s, x ;
    rf = fopen("in.dat", "r") ;
    wf = fopen("out.dat", "w") ;
    for(i = 0 ; i < 10 ; i++)
    {
       fscanf(rf, "%lf", &x) ;
       s = fun(x) ;
       fprintf(wf, "%f\n", s) ;
    }
    fclose(rf) ;
    fclose(wf) ;
}
计算机等级考试二级C语言上机题集(第81~85套)计算机等级考试二级C语言上机题集(第81~85套)

1.(1struct student  (2)n-13)a[i].name,a[j].name
2. d=1;  s=0;
    d=d/10;
3double fun(double  x)
    {
         int i=0;
         double s=1,t=1;
         while (fabs(t)>0.000001)
         {
              t=t*(0.5-i)*x/(i+1);
              s+=t;
              i++;
         }
         return s;
    }

第85套参考答案

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。