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

  48、给定程序MODI1.C中函数fun的功能是:将一个由八进制数字字符组成的字符串转换为与其面值相等的十进制整数。规定输入的字符串最多只能包含5位八进制数字字符。

      例如,若输入:77777,则输出将是:32767。

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

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

  #include

  #include

  #include

  int  fun( char *p )

  {   int   n;

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

      n= *P-'o';

      p++;

      while( *p!=0 ) {

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

        n=n*8+*P-'o';

   p++;

      }

      return  n;

  }

  main()

  {   char   s[6];     int  i;   int   n;

      printf("Enter a string (Ocatal digits):  "); gets(s);

      if(strlen(s)>5){ printf("Error: String too longer !\n\n");exit(0); }

      for(i=0; s[i]; i++)

         if(s[i]<'0'||s[i]>'7')

         {  printf("Error: %c not is ocatal digits!\n\n",s[i]);exit(0); }

      printf("The original string:  "); puts(s);

      n=fun(s);

      printf("\n%s is convered to integer number: %d\n\n",s,n);

  }

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