計算機二級考試C語言試題與答案

來源:文萃谷 5.72K

計算機二級考試在即,yjbys小編為同學們帶來最新C語言考試試題,希望對大家複習C語言有幫助!

計算機二級考試C語言試題與答案

  程序改錯

功能:一個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 huiwenn");

else

printf("this number is not a huiwenn");

}

改: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=%dn",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)

熱門標籤