考试首页 | 考试用书 | 培训课程 | 模拟考场 | 考试论坛  
全国  |             |          |          |          |          |         
  当前位置:计算机等级 > 二级考试 > C语言程序设计 > C语言模拟试题 > 文章内容
  

全国计算机二级考试C语言试题与答案精选第四套(程序改错)

中华IT学院   【 】  [ 2016年7月11日 ]

程序改错

功能:一个5位数,判断它是不是回文数。即12321是回文数,个

      位与万位相同,十位与千位相同。

 

------------------------------------------------------*/

 

#include "stdio.h"

main( )

{

  /**********ERROR**********/

  long ge,shi,qian;wan,x;

  scanf("%ld",&x);

  /**********ERROR**********/

  wan=x000;

  qian=x000/1000;

  shi=x0/10;

  ge=x;

  /**********ERROR**********/

  if (ge==wan||shi==qian)

    printf("this number is a huiwen\n");

  else

    printf("this number is not a huiwen\n");

}

改:long ge,shi,qian,wan,x;

    wan=x/10000;

if (ge==wan&&shi==qian)

 

 

 

/*------------------------------------------------------       

【程序改错】

--------------------------------------------------------

 

功能:用下面的和式求圆周率的近似值。直到最后一项的绝对值

      小于等于0.0001。

   

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

 

     

------------------------------------------------------*/

#include "stdio.h"

/**********ERROR**********/

#include "math"

 

void fun()

{

     float s=0,t=1,i=1;

  /**********ERROR**********/

     int  p=1;

  /**********ERROR**********/

  while(fabs(t)<=1e-4)

  {

    s=s+t;

    p=-p;

    i=i+2;

    t=p/i;

  }

  /**********ERROR**********/

  printf("pi=%d\n",s*4);

}

 

main()

{

  fun();

改:#include "math.h"

float  p=1;

          while(fabs(t)>1e-4)

while(0.0001

while(1e-4

while(fabs(t)>0.0001)

 

分享到:
本文纠错】【告诉好友】【打印此文】【返回顶部
将考试网添加到收藏夹 | 每次上网自动访问考试网 | 复制本页地址,传给QQ/MSN上的好友 | 申请链接 | 意见留言 TOP
关于本站  网站声明  广告服务  联系方式  站内导航  考试论坛
Copyright © 2006-2017 中华考试网(Examw.com) All Rights Reserved  营业执照