2020华师c语言程序客观题作业和答案,华师《C语言程序设计》练习题库答案.doc...

.

《C语言程序设计》试题库答案

一、选择题(下列各题有四个选项,只有一个答案是正确的,请选出正确选项)

1--5 ACDCB 6--10 ACBAB 11--15CCADB 16--20BABCD 21--25CDACC 26--30 DDBDB 31--35DADAA 36—40BCBCC 41—45CDCCB 46--50 CBAAD 51--55 BCAAC 56--60 DBBCA

61--65 CDCCD 66-70 CDDAC 71—75 CCDBC 76—80 DDBCA 81—85 CDDDB 86—90 BBBAB

二、填空题

1、 【1】1【2】2

2、 【1】4【2】8

3、 -16

4、 -32768 ~ 32767

5、 【1】单精度型(或:float)【2】双精度型(或:double)

6、 【1】整型【2】字符型【3】枚举类型

7、 1

8、 26

9、 【1】12【2】4

10、 【1】6【2】4【3】2

11、 -60

12、 2

13、 【1】10【2】6

14、 5.500000

15、 3.500000

16、 i:dec=-4,oct=177774,hex=fffc,unsigned=65532

17、 *3.140000,3.142*

18、 c:dec=120,oct=170,hex=78,ASCII=x

19、 *d(1)=-2*d(2)=-2*d(3)=-2*

*d(4)=177776*d(5)=177776*d(6)=177776*

20、 *d(1)=-2*d(2)=-2*d(3)=-2*

*d(4)=fffe*d(5)=fffe*d(6)=fffe*

21、 *d(1)=3.50000e+00*d(2)=3.500e+00*d(3)=3.500e+00*

*d(4)=-3.50000e+00*d(5)=-3.50000e+00*d(6)=-3.5000e+00*

22、 x=1 y=2 *sum*=3

10 Squared is: 100

23、 (1) 10

(2) □□□□10(□表示空格)

(3) 56.100000

(4) □□□□□□3.141600

(5) 5.68100e+02

(6) □□□3.14160e+00

(7) 3.1416

(8) □□□□□□3.1416

24、 (1) 123.456000

(2) □□□□□□□123.457

(3) 123.4560

(4) 8765.456700

(5) □□□□□□8765.457

(6) 8765.4567

(7) 8765.4567

25、 【1】可以使同一输出语句中的输出宽度得以改变。

【2】

##1

##□2

##□□3

##□□□4

##□□□□5

26、 sjhiu

27、 s=254

28、 5,5

29、 36

30、 3

31、 * *

32、 a=-5

33、i%3==2&&i%5==3&&i%7==2【2】j%5==0

34、 【1】n%10【2】max=t

35、 sum%4==0

36、 【1】s%10【2】s/10

37、 k=14 n=-1

38、 x=1,y=20

39、 1,3,7,15,

31,63,

40、 m=4 n=2

41、 i<=x

42、 2*x+4*y==90

43、 -1

44、 【1】1【2】3

45、 【1】t=t*i【2】t=-t/i

46、 【1】&a,&b【2】fabs(b-a)/n【3】sin(a+i*h)*cos(a+i*h)

47、 【1】e=1.0【2】new>=1e-6

48、 sum=19

49、 *

#

50、 * * * * #

51、 【1】k+=2【2】j!=i&&j!=k

52、 【1】m=n【2】m【3】m/=10

53、 【1】m=0,i=1【2】m+=i

54、 【1】100-i*5-j*2【2】k>=0

55、 【1】j=1【2】k>=0&&k<=6

56、 【1】常量表达式【2】常量表达式

57、 按行主顺序存放

58、 【1】0【2】4

59、 i*m+j+1

60、 【1】0【2】6

61、 10 4 6 8 2 4 6 12 2

62、 【1】&a[i]【2】i%4==0【3】printf(“\n”);

63、 【1】j<=2【2】b[j][i]=a[i][j]【3】i<=2

64、 array a:

123

456

array b:

1 4

25

36

65、 【1】j=2【2】j>=0

66、 The result is:

1

67

111213

16171819

2122232425

67、 【1】i==j【2】a[i][j]

68、 【1】m=100;m<1000【2】m/10-x*10【3】a[i]=m

69、 【1】x[i-1]+x[i-2]【2】fabs((double)(x[i-1]-x[i]))

【3】i+2

70、 The result is:

1:8

2:5

3:6

4:3

三、编成题

1、 #include

main()

{

int day = 0, buy = 2;

float sum = 0.0, ave;

do

{

sum += 0.8 * buy;

day++;

buy *= 2;

}

while (buy <= 100);

ave = sum / day;

printf(“%f”, ave);

}

2、 #include

main()

{

int i, x, y, last = 1;

printf(“Input x and y:”);

scanf(“%d%d”, &x, &y);

for (i=1; i<=y; i++)

last = last * x % 1000;

printf(“\nThe last 3 digits of %d * * %d is: %d\n”, x, y, last%1000);

}

3、 #include

main()

{

int i, j;

float g, sum, ave;

for (i=1; i<=6; i++)

{

sum = 0;

for (j=1; j<=5; j++)

{

scanf(“%f”, &g);

sum += g;

}

ave = sum / 5;

printf(“No.%d ave=%5.2f\n”, i, ave);

}

}

键盘输入:95 70 73 67 64

60 65 77 86 90

71 93 63 80 90

87 83 91 95 89

100 93 89 92 85

52 63 66 70 71

运行结果:No.1 ave=73.80

No.2 ave=75.60

No.3 ave=79.40

No.4 ave=89.00

No.5 ave=91.80

No.6 ave=64.40

4、 #define M 50

main()

{

int a[M], c[5], i, n = 0, x;

printf(“Enter 0 or 1 or 2 or 3 or 4, to end with –1\n”);

scanf(“%d”, &x);

while (x != -1)

{

if (x >= 0 && x <= 4)

{

a[n] = x;

n++;

}

scanf(“%d”, &x);

}

for (i=0; i<5; i++)

c[i] = 0;

for (i=0; i

c[a[i]]++;

printf(“The result is:\n”);

for (i=0; i<=4; i++)

printf(“%d:%d\n”,i c[i]);

printf(“\n”);

}

5、 main()

{

int a[5][4] = {3,6,2,1,3,9,0,8,2,1,5,6,7,2,7,4,0,0,0,0};

int i, j;

for (i=0; i<4; i++)

for (j=0; j<4; j++)

a[4][j] += a[i][j];

printf(“The result is:\n”);

for (i=0; i<4; i++)

printf(“%3d”, a[4][j]);

}

6、 #define SIZE 30

main()

{

float b[SIZE/5], sum;

int a[SIZE], i, j, k;

for (k=2, i=0; i

{

a[i] = k;

k += 2;

}

sum = 0.0;

for (k=0, i=0; i

{

sum += a[i];

j = i + 1;

if ((i+1)%5 == 0)

{

b[k] = sum / 5;

sum = 0;

k++;

}

}

printf(“The result is:\n”);

for (i=0; i

printf(“%5.2f ”, b[i]);

printf(“\n”);

}

7、 main()

{

int i, j, a[2][3] = {{2,4,6},{8,10,12}};

printf(“The original array is:\n”);

for (i=0; i<2; i++)

{

for (j=0; j<3; j++)

printf(“%4d”, a[i][j]);

printf(“\n”);

}

printf(“\nThe result is:\n”);

for (i=0; i<3; i++)

{

for (j=0; j<2; j++)

printf(“%4d”, a[j][i]);

printf(“\n”);

}

}

8、 main()

{

int a [5][5], i, j, n = 1;

for (i=0; i<5; i++)

for (j=0; j<5; j++)

a[i][j] = n++;

printf(“The result is:\n”);

for (i=0; i<5; i++)

{

for (j=0; j<5; j++)

printf(“%4d”, a[i][j]);

printf(“\n”);

}

}

9、 main()

{

int a[10][10], i, j, k = 0, m, n;

printf(“Enter n (n<10):\n”);

scanf(“%d”, &n);

if (n % 2 == 0)

m = n / 2;

else

m = n / 2 + 1;

for (i=0; i

{

for (j=i; j

{

k++;

a[i][j] = k;

}

for (j=i+1; j

{

k++;

a[j][n-i-1] = k;

}

for (j=n-i-2; j>=i; j--)

{

k++;

a[n-i-1][j] = k;

}

for (j=n-i-2; j>=i+1; j--)

{

k++;

a[j][i] = k;

}

}

for (i=0; i

{

for (j=0; j

printf(“%5d”, a[i][j]);

printf(“\n”);

}

}

10、 main()

{

int a[10], b[10], i;

for (i=0; i<10; i++)

scanf(“%d”, &a[i]);

for (i=1; i<10; i++)

b[i] = a[i] / a[i-1];

for (i=1; i<10; i++)

{

printf(“%3d”, b[i]);

if (i % 3 == 0)

printf(“\n”);

}

}

11、 #include

main()

{

char a[12] = “adfgikmnprs”, c;

int i, top, bot, mid;

printf(“Input a character\n”);

scanf(“%c”, &c);

printf(“c=\’%c\’\n”, c);

for (top=0, bot=10; top<=bot; )

{

mid = (top + bot) / 2;

if (c == a[mid])

{

printf(“The position is %d\n”, mid+1);

break;

}

else if (c > a[mid])

top = mid + 1;

else

bot = mid – 1;

}

if (top > bot)

printf(“* *\n”);

}

12、 #include

#include

main()

{

char a[80], b[80];

int i = 0, j;

printf(“Input two strings.\n”);

gets(a);

gets(b);

while (a[i++] != ‘\0’)

;

for (j=0, i--; j<5&&b[j]!=’\0’; j++)

a[i++] = b[j];

a[i] = ‘\0’;

puts(a);

}

13、 #include

#include

main()

{

char a[80], b[] = “ab”, max;

int i = 1, j;

printf(“Input a string\n”);

gets(a);

puts(a);

max = a[0];

while (a[i] != ‘\0’)

{

if (a[i] > max)

{

max = a[i];

j = i;

}

i++;

}

for (i=strlen(a)+2; i>j; i--)

a[i] = a[i-2];

a[i+1] = ‘a’;

a[i+2] = ‘b’;

puts(a);

}

14、 fun(int x, int y)

{

int z;

z = fabs(x-y);

return(z);

}

15、 isprime(int a)

{

int i;

for (i=2; i

if (a % i == 0)

return 0;

return 1;

}

精选范本

展开阅读全文

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值