当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言50套程序修改上机题(19)
发布时间:2011/11/1 9:57:27 来源:城市学习网 编辑:ziteng

  19、给定程序MODI1.C中函数fun的功能是:首先把b所指字符串中的字符按逆序存放, 然后将a所指字符串中的字符和b所指字符串中的字符,按排列的顺序交叉合并到c所指数组中,过长的剩余字符接在c所指数组的尾部。例如,当a所指字符串中的内容为"abcdefg",b所指字符串中的内容为"1234"时,c所指数组中的内容应该为"a4b3c2d1efg";而当a所指字符串中的内容为"1234",b所指字符串中的内容为"abcdefg"时,c所指数组中的内容应该为"1g2f3e4dcba"。

      请改正程序中的错误,使它能得出正确的结果。

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

  #include

  #include

  void fun( char  *a, char  *b, char  *c )

  {

    int   i , j;     char   ch;

    i = 0;    j = strlen(b)-1;

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

    while ( i > j )

    {   ch = b[i]; b[i] = b[j]; b[j] = ch;

        i++;    j--;

    }

    while ( *a || *b ) {

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

       If ( *a )

         { *c = *a;  c++; a++; }

       if ( *b )

         { *c = *b;  c++; b++; }

    }

    *c = 0;

  }

  main()

  {

    char   s1[100],s2[100],t[200];

    printf("\nEnter s1 string : ");scanf("%s",s1);

    printf("\nEnter s2 string : ");scanf("%s",s2);

    fun( s1, s2, t );

    printf("\nThe result is : %s\n", t );

  }

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved