第16套

1.程序填空题

给定程序中,函数fun的功能是:统计出带有头结点的单向链表中结点的个数,存放在形参n所指的存储单元中。

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

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

#include  <stdio.h>
#include  <stdlib.h>
#define  N    8
typedef  struct list
{  
    int  data;
    struct list  *next;
} SLIST;
SLIST *creatlist(int  *a);
void outlist(SLIST  *);
void fun( SLIST  *h, int  *n)
{  
    SLIST  *p;
    /**********found**********/
    ___1___=0;
    p=h->next;
    while(p)
    {  
        (*n)++;
    /**********found**********/
        p=p->___2___;
    }
}
int main()
{  
    SLIST  *head;
    int  a[N]={12,87,45,32,91,16,20,48}, num;
    head=creatlist(a);    
    outlist(head);
    /**********found**********/
    fun(___3___, &num);
    printf("\nnumber=%d\n",num);
    return 0;
}
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("->End\n");
    }
}

2.程序修改题

给定程序中,函数fun的功能是:计算整数n的阶乘。

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

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

#include <stdio.h>
double fun(int n)
{
   double result=1.0;
   while (n>1 && n<170)
   /*********found*********/
     result*=--n;
   /*********found*********/
   return result
}
int main()
{
   int n;
   printf("Enter an integer: ");
   scanf("%d",&n);
   printf("\n\n%d!=%g\n\n",n,fun(n));
   return 0;
}

3.程序设计题

编写函数fun,它的功能是:从s所指的字符串中删除给定的字符。同一字母的大、小写按不同字符处理。

若程序执行时,输入字符串为:turbo c and borland c++

从键盘输入字符:n,则输出字符串为:turbo c ad borlad c++。

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

#include <stdio.h>
#include <string.h>
void NONO(void);
void fun(char s[],char c)
{

}
int main()
{
    char str[]="turbo c and borland c++";
    char ch;
    printf("原始字符串:%s\n", str);
    printf("输入一个字符:");
    scanf("%c",&ch);
    fun(str,ch);
    printf("str[]=%s\n",str);
    NONO();
    return 0;
}
void NONO(void)
{
 /* 请在此函数内打开文件,输入测试数据,调用 fun 函数,
    输出数据,关闭文件。 */
    FILE *rf, *wf ;
    char s[81], ch, w ;
    int len ;
    rf = fopen("in.dat","r") ;
    wf = fopen("out.dat","w") ;
    fgets(s, 80, rf) ;
    fscanf(rf, "%c", &ch) ;
    len = strlen(s) - 1 ;
    w = s[len] ;
    if(w == '\n' || w == 0x1a) s[len] = 0 ;
    fun(s, ch) ;
    fprintf(wf, "%s", s) ;
    fclose(rf) ;
    fclose(wf) ;
}

1.(1)*n   (2)next   (3)head
2. result*=n--;
      return result;
3void fun(char s[],char c)
      {
           int i,j;
           for (i=0,j=0; s[i]!='\0';i++)
               if (s[i]!=c) s[j++]=s[i];
           s[j]='\0';
      }

第16套参考答案

第17套

1.程序填空题

给定程序通过定义并赋初值的方式,利用结构体变量存储了一名学生的学号、姓名和3门课的成绩。函数fun的功能是将该学生的各科成绩都乘以一个系数a。

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

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

#include    <stdio.h>
typedef  struct
{  
    int  num;
    char  name[9];
    float  score[3];
}STU;
void show(STU  tt)
{  
    int  i;
    printf("%d  %s  :  ",tt.num,tt.name);
    for(i=0; i<3; i++)
      printf("%5.1f",tt.score[i]);
    printf("\n");
}
/**********found**********/
void modify(___1___  *ss,float  a)
{  
    int  i;
    for(i=0; i<3; i++)
    /**********found**********/
       ss->___2___ *=a;
}
int main( )
{  
    STU  std={ 1,"Zhanghua",76.5,78.0,82.0 };
    float  a;
    printf("\nThe original number and name and scores :\n");
    show(std);
    printf("\nInput a number :   ");  scanf("%f",&a);
    /**********found**********/
    modify(___3___,a);
    printf("\nA result of modifying :\n");
    show(std);
    return 0;
}

2.程序修改题

给定程序中,函数fun的功能是:用下面的公式求π的近似值,直到最后一项的绝对值小于指定的数num为止。

π/4=1-1/3+1/5-1/7+…

例如,程序运行后,输入0.0001,则程序输出3.1414。

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

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

#include <stdio.h>
#include <math.h>
float fun(float num)
{   
    int s ;
    float n, t, pi ;
    t = 1 ; pi = 0 ; n = 1 ;  s = 1 ;
    /**************found**************/
    while(t >= num)
    {
        pi = pi + t ;
        n = n + 2 ;
        s = -s ;
    /**************found**************/
        t = s % n ;
    }
    pi = pi * 4 ;
    return pi ;
}
int main( )
{   
    float n1, n2 ;
    printf("Enter a float number: ") ;
    scanf("%f", &n1) ;
    n2 = fun(n1) ;
    printf("%6.4f\n", n2) ;
    return 0;
}

3.程序设计题

编写函数fun,它的功能是:删除一个字符串中指定下标的字符。其中,a指向原字符串,删除后的字符串存放在b所指数组中,n中存放指定的下标。

例如,输入一个字符串:World,然后输入3,则调用该函数后的结果为Word。

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

#include <stdio.h>
#include <string.h>
#define LEN 20
void NONO(void);
void fun (char a[], char b[], int n)
{

}
int main()
{
    char str1[LEN], str2[LEN] ;
    int n ;
    printf("Enter the string:\n") ;
    gets(str1) ;
    printf("Enter the position of the string deleted:") ;
    scanf("%d", &n) ;
    fun(str1, str2, n) ;
    printf("The new string is: %s\n", str2) ;
    NONO() ;
    return 0;
}
void NONO(void)
{/* 本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/
    char str1[LEN], str2[LEN] ;
    int i, n ;
    FILE *rf, *wf ;
    rf = fopen("in.dat","r") ;
    wf = fopen("out.dat","w") ;
    for (i = 0 ; i < 10 ; i++)
    {
       fscanf(rf, "%s %d", str1, &n) ;
       fun(str1, str2, n) ;
       fprintf(wf, "%s\n", str2) ;
    }
    fclose(rf) ;
    fclose(wf) ;
}

1.(1)STU   (2)score[i]   (3)&std
2while(fabs(t) >= num)
      t = s / n ;
3void fun (char a[], char b[], int n)
     {
          int i,j;
         for (i=0,j=0;a[i]!='\0';i++)
             if (i!=n) b[j++]=a[i];
         b[j]='\0';
     }

第17套参考答案

第18套

1.程序填空题

给定程序中,函数fun的功能是:从三个形参a,b,c中找出中间的那个数,作为函数值返回。

例如,当a=3,b=5,c=4时,函数返回值为:4。

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

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

#include    <stdio.h>
int fun(int  a, int  b, int  c)
{
   int  t;
   /**********found**********/
   t=(a>b)?(b>c? b:(a>c?c:___1___)):((a>c)?___2___:((b>c)?c:___3___));
   return  t;
}
int main()
{  
   int  a1=3, a2=5, a3=4, r;
   r = fun(a1, a2, a3);
   printf("\nThe middle number is  :  %d\n", r);
   return 0;
}

2.程序修改题

给定程序中,函数fun的功能是:逐个比较p,q所指的两个字符串对应位置中的字符,把ASCII值大或相等的字符依次存放到c数组中,形成一个新的字符串。

例如,若a中字符串为:aBCDeFgH,b中的字符串为:ABcd,则c中的字符串应为:aBcdeFgH。

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

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

#include <stdio.h>
#include <string.h>
void fun(char *p,char *q,char *c)
{ 
   /************found************/ 
   int k=1;
   /************found************/
   while (*p!=*q)
   {  
       if (*p<*q)  c[k]=*q;
       else        c[k]=*p;
       p++;
       q++;
       k++;
   }
}
int main()
{   
   char a[10]="aBCDeFgH",b[10]="ABcd",c[80]={'\0'};
   fun(a,b,c);
   printf("The string a:  ");  puts(a);
   printf("The string b:  ");  puts(b);
   printf("The result   : ");  puts(c);
   return 0;
}

3.程序设计题

编写函数fun,它的功能是:将s所指字符串中ASCII码值为偶数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。

例如,若s所指的字符串中的内容为:ABCDEFG12345,则t所指的数组中的内容应为:ACEG135。

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

#include <stdio.h>
#include <string.h>
void NONO(void);
void fun(char *s,char t[])
{

}
int main()
{
    char s[100],t[100];
    printf("\nPlease enter string S:");scanf("%s",s);
    fun(s,t);
    printf("\nThe result is: %s\n",t);
    NONO();
    return 0;
}
void NONO(void)
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
    char s[100], t[100] ;
    FILE *rf, *wf ;
    int i ;
    rf = fopen("in.dat", "r") ;
    wf = fopen("out.dat", "w") ;
    for(i = 0 ; i < 10 ; i++)
    {
       fscanf(rf, "%s", s) ;
       fun(s, t) ;
       fprintf(wf, "%s\n", t) ;
    }
    fclose(rf) ;
    fclose(wf) ;
}

1.(1)a   (2)a   (3)b
2int k=0;
      while (*p!='\0' || *q!='\0')
3void fun(char *s,char t[])
      {
          int i,j;
          for (i=0,j=0;s[i]!='\0';i++)
              if (s[i]%2!=0) t[j++]=s[i];
          t[j]='\0';
      }

第18套参考答案

第19套

1.程序填空题

给定程序中,函数fun的功能是:计算

直到|xn/n!|<10-5

例如,若x=2.5,函数值为:1.917915。

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

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

#include  <stdio.h>
#include  <math.h>
double fun(double  x)
{  
    double  f, t;      
    int  n;
    f = 1.0 + x;
    /**********found**********/
    t = ___1___;
    n = 1;
    do {
      n++;
    /**********found**********/
      t *= (-1.0)*x/___2___;
      f += t;
    }
    /**********found**********/
    while (___3___ >= 1e-6);
    return  f;
}
int main()
{   
    double x, y;
    x = 2.5;
    y = fun(x);
    printf("\nThe result is :\n");
    printf("x=%-12.6f y=%-12.6f\n", x, y);
    return 0;
}

2.程序修改题

给定程序中,函数fun的功能是:求k!(k<13),所求阶乘值作为函数值返回。

例如,若k=10,函数值为:3628800。

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

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

#include <stdio.h>
long  fun (int k)
{
    /************found************/
    if  (k<0)
      return (k*fun(k-1));
    /************found************/
    else if ( k=0 )
        return 1L;
    else return 0;
}
int main()
{  
    int k = 10 ;
    printf("%d!=%ld\n", k, fun(k));
    return 0;
}

3.程序设计题

编写函数fun,它的功能是:将大于整数m且紧靠m的k个素数存入xx所指的数组中。

例如,若输入17  5,则应输出:19 23 29 31 37。

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

#include <stdio.h>
void NONO(void);
void fun(int m,int k,int xx[])
{

}
int main()
{
    int m,n,zz[1000];
    printf("\nPlease enter two integers:");
    scanf("%d%d",&m,&n);
    fun(m,n,zz);
    for(m=0;m<n;m++)
       printf("%d ",zz[m]);
    printf("\n");
    NONO( ) ;
    return 0;
}
void NONO(void)
{/* 本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/
    int m, n, zz[1000], i ;
    FILE *rf, *wf ;
    rf = fopen("in.dat", "r") ;
    wf = fopen("out.dat", "w") ;
    for(i = 0 ; i < 10 ; i++)
    {
       fscanf(rf, "%d %d", &m, &n) ;
       fun(m, n, zz) ;
       for (m=0; m<n; m++) fprintf(wf, "%d ",zz[m]);
       fprintf(wf, "\n") ;
    }
    fclose(rf) ;
    fclose(wf) ;
}

1.(1)x   (2)n   (3)fabs(t)
2if  (k>0)
      else if ( k==0 )
3void fun(int m,int k,int xx[])
      {
           int x,i,n;
           x=m+1;
           n=0;
           while (n<k)
           {
                for (i=2;i<=x/2;i++)
                     if (x%i==0) break;
                 if (i>x/2) xx[n++]=x;
                 x++;
           }
       }

第19套参考答案

第20套

1.程序填空题

给定程序中,函数fun的功能是:将N*N矩阵主对角线上元素的值与反向对角线对应位置上的元素值进行交换。

例如,N=3,有下列矩阵

1 2 3

4 5 6

7 8 9

交换后为:

3 2 1

4 5 6

9 8 7

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

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

#include  <stdio.h>
#define  N  4
/**********found**********/
void fun(int  ___1___ , int  n)
{  
    int  i,s;
    /**********found**********/
    for(___2___; i++)
    {  
       s=t[i][i];
       t[i][i]=t[i][n-i-1];
    /**********found**********/
       t[i][n-1-i]=___3___;
    }
}
int main()
{  
    int  t[][N]={21,12,13,24,25,16,47,38,
           29,11,32,54,42,21,33,10}, i, j;
    printf("\nThe original array:\n");
    for(i=0; i<N; i++)
    {  
        for(j=0; j<N; j++)  printf("%d  ",t[i][j]);
        printf("\n");
    }
    fun(t,N);
    printf("\nThe result is:\n");
    for(i=0; i<N; i++)
    {
        for(j=0; j<N; j++)  printf("%d  ",t[i][j]);
        printf("\n");
    }
    return 0;
}

2.程序修改题

给定程序的功能是:读入一个英文文本行,将其中每个单词的第一个字母改成大写,然后输出此文本行(这里的单词指由空格隔开的字符串)。

例如,若输入:I am a student to take the examination,

则应输出:I Am A Student To Take The Examination。

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

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

#include <ctype.h>
#include <string.h>
/************found************/
include  (stdio.a)
/************found************/
upfst(char  p)
{  
    int  k=0;
    for ( ; *p; p++)
      if (k)
      {   if ( *p == ' ' )   k = 0;   }
      else  if ( *p != ' ' )
      {   k = 1;   *p = toupper( *p ); }
}
int main()
{   
    char  chrstr[81];
    printf("\nPlease enter an English text line: ");   
    gets(chrstr);
    printf("\n\nBefore changing:\n  %s", chrstr);
    upfst(chrstr);
    printf( "\nAfter changing:\n  %s\n", chrstr);
    return 0;
}

3.程序设计题

编写函数fun,它的功能是:求出二维数组w对应的N*N矩阵周边元素的平均值。

例如,若矩阵为

0 1 2 7 9

1 9 7 4 5

2 3 8 3 1

4 5 6 8 2

5 9 1 4 1

则函数的返回值应为:3.375000。

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

#include <stdio.h>
#include <stdlib.h>
#define  N  5
void NONO(void);
double fun(int w[][N])
{

}
int main()
{
    int a[N][N]={0,1,2,7,9,1,9,7,4,5,
            2,3,8,3,1,4,5,6,8,2,5,9,1,4,1};
    int i, j;
    double s ;
    printf("***** The array *****\n");
    for ( i =0;  i<N; i++)
    {
        for ( j =0; j<N; j++ )
        {  printf( "%4d", a[i][j] ); }
        printf("\n");
    }
    s = fun ( a );
    printf ("***** THE  RESULT *****\n");
    printf( "The sum is :  %f\n",s );
    NONO( );
    return 0;
}
void NONO(void)
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
    FILE *rf, *wf ;
    int i, j, a[5][5];
    double s ;
    rf = fopen("in.dat","r") ;
    wf = fopen("out.dat","w") ;
    for(i = 0 ; i < 5 ; i++)
       for(j = 0 ; j < 5 ; j++)
          fscanf(rf, "%d ", &a[i][j]) ;
    s = fun(a) ;
    fprintf(wf, "%lf\n", s);
    fclose(rf) ;
    fclose(wf) ;
}

1.(1)t[][N]   (2)i=0;i<N   (3)s
2. #include  <stdio.h>
      void upfst(char  *p)
3double fun(int w[][N])
      {
           int s=0,i;
           for (i=0;i<N;i++)
               s+=w[0][i]+w[N-1][i]+w[i][0]+w[i][N-1];
           s=s-w[0][0]-w[0][N-1]-w[N-1][0]-w[N-1][N-1];
           return s/(4.0*N-4.0);
       }

第20套参考答案

原文地址:http://www.cnblogs.com/cs-whut/p/16857018.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性