您的当前位置:首页正文

北交大C语言期末试题 C-06-07-1参考答案

来源:个人技术集锦
答题卡

一、填空题:

1. 地址传递(或双向传递) 2. 动态 3. 3 4. x >= 10 | | y+z >= 6 5. 1 6. 5 7. 1 8. ‘\\0’ 9. 0 10. 返回指向整型指针的函数名 11. 25 12. 5 13. 5 14. gets (str) 15. 4 16. 函数 17. 1+rand ( ) %6 18. 10 19. 文本(或ASCII码) 20. rb

二、阅读程序写结果:

1. 105 2. Zlzyd! 3. a=1, b=2 4. 6, 8 5. 1, 3 6. 4

三、程序填空题:

(1) (2) a % i = = 0 (3) isprime ( iNumber ) (4) p+n-1 (5) q-- (6) pa=a (7) i=0; i<10; i++ (8) m =( t + b) / 2 (9) x < a[m] (10) t <= b && find == 0

四、编程题:

1

1. 输入n的值,输出如图所示高为n的等腰三角形(例如,下图为n=6时的等腰三角形)。

*

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

参考程序:

#include void main ( ) {

int i,j,n;

printf(\"\\nPlease Enter n:\"); scanf(\"%d\; for(i=1;i<=n;i++)

{ for(j=1;j<=n-i;j++)

printf(\" \");

for(j=1;j<=2*i-1;j++) printf(\"*\"); printf(\"\\n\"); } }

2. 求这样一个三位数,该三位数等于其每位数字的阶乘之和(通过调用自定义函数计算阶乘)。即: abc = a! + b! + c!

参考程序:

#include int f (int m) { int i=0, t=1;

while (++i <= m) t* = i; return(t); }

void main ( )

2

{

int a[5], i, t, k;

for (i=100;i<1000;i++)

{ for ( t=0,k=1000;k>=10;t++) { a[t]=(i%k)/(k/10); k/=10; }

if (f (a[0])+f (a[1])+f (a[2])= = i ) printf(\"%d \; }

}

3. 从键盘输入一行字符,统计其中字母、空格、数字以及其它字符的个数。

参考程序:

#include void main() {

char str[80];

int alphabet=0,digit=0 , space=0 , other=0, i=0; gets ( str );

for ( i = 0 ; str[i] != ‘\\0’; i++ )

if (‘A’<= str[i] && str[i] <=‘Z’||‘a’<= str[i] && str[i] <=‘z’) ++ alphabet;

else if ( str[i] = = ‘ ’ ) ++space;

else if ( str[i] <= ‘9’ && str[i] >= ‘0’) ++digit; else

++other;

printf(“有%d个字母,%d个空格,%d个数字,%d个其他字符:\\n”, alphabet, space, digit, other); }

3

因篇幅问题不能全部显示,请点此查看更多更全内容