2012全国计算机二级C语言(C++)题库 第7套题(一)

时间:2011-12-24 23:56:50

微信搜索关注"91考试网"公众号,领30元,获取事业编教师公务员等考试资料40G

7套题

一、程序填空题

#include    <stdio.h>

#include    <stdlib.h>

#define    N    8

typedef  struct list

{  int  data;

   struct list  *next;

} SLIST;

void  fun( SLIST *h)

{  SLIST  *p, *q;

   p=h->next;

   if (p!=NULL)

   {  q=p->next;

      while(q!=NULL)

      {  if (p->data==q->data)

         {  p->next=q->next;

/**********found**********/

            free(___1___);

/**********found**********/

            q=p->___2___;

         }

         else

         { p=q;

/**********found**********/

           q=q->___3___;

         }

      }

   }

}

SLIST *creatlist(int  *a)

{  SLIST  *h,*p,*q;      int  i;

   h=p=(SLIST *)malloc(sizeof(SLIST));

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

   {  q=(SLIST *)malloc(sizeof(SLIST));

      q->data=a[i];  p->next=q;  p=q;

   }

   p->next=0;

   return h;

}

void outlist(SLIST  *h)

{  SLIST  *p;

   p=h->next;

   if (p==NULL)  printf("nThe list is NULL!n");

   else

   {  printf("nHead");

      do { printf("->%d",p->data);  p=p->next;    } while(p!=NULL);

      printf("->Endn");

  }

}

main( )

{  SLIST  *head;      int  a[N]={1,2,2,3,4,4,4,5};

   head=creatlist(a);

   printf("nThe list before deleting :n");  outlist(head);

   fun(head);

   printf("nThe list after deleting :n");  outlist(head);

}

 

 

二、程序改错题

#include <stdio.h>

#define  N  20

 

void  fun(int a[], int n)

{ int i, j, t, p;

  for (j = 0 ;j < n-1 ;j++) {

/************found************/

    p = j

    for (i = j+1;i < n; i++)

      if(a[i] < a[p])

/************found************/

        p = j;

    t = a[p] ; a[p] = a[j] ; a[j] = t;

  }

}

 

main()

{

  int a[N]={9,6,8,3,-1},i, m = 5;

  printf("排序前的数据:") ;

  for(i = 0;i < m;i++) printf("%d ",a[i]); printf("n");

  fun(a,m);

  printf("排序后的数据:") ;

  for(i = 0;i < m;i++) printf("%d ",a[i]); printf("n");

}

 

 

三、程序编写题

#include <stdio.h>

#define M 100

void  fun ( int  m, int *a , int *n )

{

 


首页 上页 1 2 下页 尾页 1/2/2
微信搜索关注"91考试网"公众号,领30元,获取公务员事业编教师考试资料40G
【省市县地区导航】【考试题库导航】

电脑版  |  手机版  |  返回顶部