C语言程序设计课后题答案(7)

2019-05-17 19:01

} } main() { int n,sum; clrscr();

printf(\scanf(\sum=fun(n);

printf(\}

—————————————————————————————————————— 11.14 请用递归函数,求裴波拉契级数,求n阶裴波拉契级数的公式如下。 ※程序如下※ #include fac(int n) { long t; if(n==0||n==1) return 1; else {

t=fac(n-1)+fac(n-2); return t; } } main() { int n;

printf(\scanf(\printf(\}

***************End of Chapter 11******************* 第十二章 C语言中用户标识符的作用域和存储类 ************************************************** 一、选择题

(1) C (2) B (3) A (4) C (5) D (6) B (7) A (8) C 二、选择题

(9) 2 ,5 ,1 3 ,2 ,-2 (10)2 4 6 8

***************End of Chapter 12*******************

第十三章 编译预处理和动态存储分配

************************************************** 一、选择题

(1) A (2) C (3) B (4) C (5) D (6) D (7) D 二、选择题

(8) a r = 9 a r = 9 a r = 1 1 (9) i n t * , s , *b 三、选择题

—————————————————————————————————————— 13.10 编写出一个宏定义MYALPHA(C),用以判断C是否是字母字符,若是得1,否则得0。 ※程序如下※ #include #include

#define MYALPHA(C) isalpha(C)?1:0 main() { char ch; clrscr(); ch=getchar(); if(MYALPHA(ch)) printf(\else

printf(\}

—————————————————————————————————————— 13.11 请写出一个宏定义swap(t,x,y)用以交换t类型的两个参数。提示:用复合语句的形式。 ※程序如下※ #include

#define swap(t,x,y) {t=x;x=y;y=t;} main() { int a,b,t; clrscr();

printf(\scanf(\swap(t,a,b);

printf(\}

——————————————————————————————————————

13.12 请编写程序,利用malloc函数开辟动态存储单元,存放输入的三个整数。然后按从小到大的顺序输出这三个数。 ※程序如下※

#include #include void main() {

int *pData = (int*)malloc(sizeof(int)*3); int t;

printf(\scanf(\

for (int i=0; i<2; i++) for (int j=i+1; j<3; j++) if (*(pData+i) > *(pData+j)) {

t = *(pData+j);

*(pData+j) = *(pData+i); *(pData+i) = t; }

printf(\}

***************End of Chapter 13******************* 第十四章 结构体、共用体和用户定义类型

************************************************** 一、选择题

(1) D (2) D (3) D (4) A (5) C (6)C (7) C (8)B 二、填空题 (9) struct link *next (10) p->next , p->data < m

(11) struct list * , list , struct list * , list , return h 三、编程题

—————————————————————————————————————— 14.12 设有以下结构类型说明: struct stud {

char num[5],name[10]; int s[4]; double ave; }; 请编写:

(1)函数readrec把30名学生的学号、姓名、四项成绩以及平均分放在一个结构体数组中,学生的学号、姓名和四项成绩由键盘输入,然后计算平均分放在结构体对应的域中。 (2)函数writerec输出30名学生的记录。

(3)main函数调用readrec函数和writerec函数,实现全部程序功能(注:不允许使用全局变量,函数之间的数据全部使用参数传递)。 ※程序如下※ #include

#define STUDNUM 30 struct stud {

char num[5],name[10]; int s[4]; double ave; };

void readrec(struct stud *pStud, int num) { int i;

printf(\

for (i=0; iBR> { printf(\

scanf(\&(pStud->s[1]),&(pStud->s[2]),&(pStud->s[3]));

pStud->ave=(pStud->s[0]+pStud->s[1]+pStud->s[2]+pStud->s[3])/4.0; pStud++; } }

void writerec(struct stud *pStud, int num) { int i;

printf(\

for (i=0; iBR> { printf(\

printf(\pStud->s[0],pStud->s[1],pStud->s[2],pStud->s[3],pStud->ave); pStud++; } }

void main() {

struct stud student[STUDNUM];

readrec(student,STUDNUM); writerec(student,STUDNUM); }

——————————————————————————————————————

14.13 已知head指向一个带头节点的单向链表,链表中每个节点包含数据区域(data)和指针域(next),数据域为整型。请分别编写函数,在链表中查找数据域值最大的节点。 ※程序如下※ #include #include struct node { int data; struct node *next; };

struct node *SearchMax(struct node *head) { int max;

struct node *pMaxNode,*pNode;

pNode = head; pMaxNode = NULL; while (pNode != NULL) {

if (pNode->data > max || pMaxNode == NULL) {

max = pNode->data; pMaxNode = pNode; }

pNode = pNode->next; }

return pMaxNode; }

void main() {

struct node *head,*tail,*pNode; int data;

printf(\

head = tail = NULL;


C语言程序设计课后题答案(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:推荐下载 初中英语多元教学法的探究-最新

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: