山东教师资格证2011心理学课后题答案 第10套题

时间:2011-12-25 00:00:09

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

10套题

一、程序填空题

#include    <stdio.h>

#include    <stdlib.h>

#define    N    8

typedef  struct list

{  int  data;

   struct list  *next;

} SLIST;

SLIST *creatlist(int  *);

void outlist(SLIST  *);

int fun( SLIST  *h)

{  SLIST  *p;         int  s=0;

   p=h->next;

   while(p)

   {

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

      s+= p->___1___;

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

      p=p->___2___;

   }

   return s;

}

main()

{  SLIST  *head;

   int  a[N]={12,87,45,32,91,16,20,48};

   head=creatlist(a);    outlist(head);

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

   printf("nsum=%dn", fun(___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("The list is NULL!n");

   else

   {  printf("nHead  ");

      do

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

      while(p!=NULL);

      printf("->Endn");

  }

}

 

 

二、程序改错题

#include  <stdio.h>

#include  <string.h>

 

void fun (char  *s,  char *t1, char *t2 , char *w)

{

  char   *p , *r, *a;

  strcpy( w, s );

  while ( *w )

  { p = w;   r = t1;

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

    while ( r )

      if ( *r == *p )  { r++;  p++; }

      else  break;

    if ( *r == '' )

    {   a = w;  r = t2;

        while ( *r ){

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

          *a = *r; a++; r++

        }

        w += strlen(t2) ;

    }

    else w++;

  }

}

 

main()

{

  char   s[100], t1[100], t2[100], w[100];

  printf("nPlease enter string S:"); scanf("%s", s);

  printf("nPlease enter substring t1:"); scanf("%s", t1);

  printf("nPlease enter substring t2:"); scanf("%s", t2);

  if ( strlen(t1)==strlen(t2) ) {

    fun( s, t1, t2, w);

    printf("nThe result is :  %sn", w);

  }

  else  printf("Error : strlen(t1) != strlen(t2)n");

}

 

 

三、程序编写题

#include <stdio.h>

#include <string.h>

void fun(char *s, char t[])

{

 

 

 

}

 

main()

{

  char   s[100], t[100];

  void NONO (  );

  printf("nPlease enter string S:"); scanf("%s", s);

  fun(s, t);

  printf("nThe result is: %sn", t);

  NONO();

}

 

void NONO (  )

{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */

  char s[100], t[100] ;

  FILE *rf, *wf ;

  int i ;

 

  rf = fopen("K:\k01\24010001\in.dat","r") ;

  wf = fopen("K:\k01\24010001\out.dat","w") ;

  for(i = 0 ; i < 10 ; i++) {

    fscanf(rf, "%s", s) ;

    fun(s, t) ;

    fprintf(wf, "%sn", t) ;

  }

  fclose(rf) ;

  fclose(wf) ;

}

 


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

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