c语言程序设计(胡宏智)第五六七八章课后答案(2)

2019-03-28 15:26

{

int i,j,total,k,sum; char *p; i=0;total=0; p=str;

while(*(p+i)!='\\0') /*p1字符串是否结束*/ {

k=i; sum=0;

while(*(p+k)==ch) /*k移动到不要删除位置*/ { k++;

sum++; /*删除字符个数*/ }

total+=sum; if (*(p+i)==ch)

{ for(j=i;*(p+j+sum)!='\\0';j++) *(p+j)=*(p+j+sum); *(p+j)='\\0'; } i++; }

return total; }

【习题6-24】

#include \#include \

void reversestr(char * str) ; void main() { char str[50];

printf(\ gets(str);

reversestr(str); printf(\}

void reversestr(char *str) {

char ch,*p1,*p2; p1=str;p2=str; while(*p2!='\\0') { p2++; } p2--;

while(p1

ch=*p1; *p1=*p2; *p2=ch; p1++; p2--; } }

习题七参考答案:

一、单选题

【习题7-1】~ 【习题7-5】: BDACB 【习题7-6】~ 【习题7-10】:BCCDA 【习题7-11】~【习题7-15】:ACACC 【习题7-16】~【习题7-20】:BCCDC 【习题7-21】~【习题7-24】:DABB 二、编写程序题

【习题7-25】参考程序:

#include \#include \struct book {

char name[30]; int price; };

main() {

int i;

struct book books[10]; clrscr();

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

printf(\ gets(books[i].name);

printf(\ scanf(\ getchar(); }

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

printf(\

puts(books[i].name);

printf(\ } }

【习题7-26】:参考程序:

#include \struct student {int num;

char name[8]; int score1; int score2; int score3; int score4; float ave;

};

void fun1(struct student stu[]) {int i;

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

printf(\

scanf(\ printf(\ scanf(\ printf(\

scanf(\ printf(\

scanf(\ printf(\

scanf(\ printf(\

scanf(\

stu[i].ave=(stu[i].score1+stu[i].score2+stu[i].score3+stu[i].score4)/4.0;

} }

void fun2(struct student stu[]) {int i;

printf(\

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

printf(\

,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score4,stu[i].ave);

}

main() {int i;

struct student stu1[2]; clrscr(); fun1(stu1); fun2(stu1); }

【习题7-27】参考程序:

#include \struct complex {

int rp; int ip; };

struct complex input(struct complex plural) {

printf(\ scanf(\

printf(\ scanf(\ return plural; }

void output(struct complex plural) {

printf(\}

struct complex add(struct complex plu1,struct complex plu2) {

struct complex plu;

plu.rp=plu1.rp+plu2.rp; plu.ip=plu1.ip+plu2.ip; return plu; }

main() {

struct complex plu1,plu2,plu; plu1=input(plu1); plu2=input(plu2); plu=add(plu1,plu2); output(plu); }

【习题7-28】参考程序:

struct node *Merge(struct node *h1,struct node *h2) {

struct node *p,*q,*r,*s,*h; p=h1;q=h2;

if(p->numnum)

{h=s=p;r=p;p=p->next;r->next=NULL;} else

{h=s=q;r=q;q=q->next;r->next=NULL;} while(p&&q) {

if(p->numnum) {r=p;p=p->next;} else

{r=q;q=q->next;} s->next=r; s=s->next;

}

if(p)

s->next=p; else

s->next=q; return h; }

【习题7-29】参考程序:

#include \#include \struct chicken {

int cock; int hen; int chick; }ch[20]; main() {

int i,j,k,n=0;

struct chicken *p; for(i=0;i<=100/5;i++) for(j=0;j<=100/3;j++) for(k=0;k<=100*3;k++)

if(i+j+k==100&&i*5+j*3+k/3.0==100.00) {

ch[n].cock=i; ch[n].hen=j; ch[n].chick=k; n++; } p=ch;

for(i=0;i

printf(\ p++; } }

习题八参考答案:

一、单选题

【习题8-1】~【习题8-5】:BCCCC 【习题8-6】~【习题8-10】:ABADB 【习题8-11】~【习题8-12】:AC 二、简答题


c语言程序设计(胡宏智)第五六七八章课后答案(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:iso9000内审员培训案例练习_24989

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

马上注册会员

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