TOP

2012全国计算机二级C语言(C++)题库 第7套题(一)
2011-12-24 23:56:50 来源: 作者: 【 】 浏览:306次 评论:0
微信搜索关注"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("->End\n");

  }

}

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 )

{

 

Tags: 责任编辑:91kaoshiwang
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇山东教师资格证2011心理学课后题.. 下一篇2012全国计算机二级C语言(C++)题..

相关栏目

最新文章

推荐文章

网站客服QQ: 960335752 - 14613519 - 48225117