谭浩强(第三版)C语言的课后答案 要第13章

作者&投稿:贠庙 (若有异议请与网页底部的电邮联系)
求谭浩强的c语言程序设计的课后习题答案 (第三版)~

已经发你了,你查看下


我买的书今天才到 很便宜的 你去当当网买吧。才10几块钱一本 !

第十三章

13.4从键盘输入一个字符串,将其中的小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存。输入的字符串以“!”结束。

解:#include <stdio.h>

main()

{

File *fp;

Char str[100];

Int I=0;

If((fp=fopen(“test”,”w”)==NULL)

{printf(“Can not open the file\n”);

exit(0);

}

printf(“Input a string:\n”);

gets(str);

while(str[i]!=’!’)

{if (str[i]>=’a’&&str[i]<=’z’)

str[i]=str[I-32];

fputc(str[i],fp);

I++;

}

fclose(fp);

fp=fopen(“test”,”r”);

fgets(str,strlen(str)+1,fp);

printf(“%s\n”,str);

fclose(fp);

}

13.5有两个磁盘文件”A”和”B”,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列),输出到一个新文件”C”中。

解:#include<stdio.h>

main()

{

FILE *fp;

Int I,j,n,i1;

Char c[100],t ,ch;

If((fp=fopen(“a1”,”r”))==NULL)

{printf(“can not open the file\n”);

exit(0);

}

printf(“\n file A:\n”);

for(I=0;(ch=fgetc(fp)!=EOF;I++)

{c[i]=ch;

putchar(c[i]);

}

fclose(fp);

i1=I;

if((fp=fopen(“b1”,”r”))==NULL)

{printf(“\n can not ipen the file”);

exit(0);

}

printf(“\n file B:\n”);

for(I=i1;(ch=fgenc(fp))!=EOF;I++)

{c[i]=ch;

putchar(c[i]);

}

fclose(fp);

n=I;

for(i=0;I<n;I++)

for(j=I+1;j<n;j++)

if(c[i]>c[j])

{t=c[i];

c[i]=c[j];

c[j]=t;

printf(“\n file C:\n”);

fp=fopen(“c1”,”w”);

for(I=0;I<n;I++)

{putc(c[i],fp);

putchar(c[i]);

}

fclose(fp);

}

13.6有5个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号、姓名、三门课成绩),计算出平均成绩,将原有数据和计算出的平均分数存放在磁盘文件stud中。

解:

#include<stdio.h>

struct student

{char num[10];

char name[8];

int score[3];

float ave;

}stu[5];

main()

{int I,j,sum;

FILE *fp;

For(I=0;I<5;I++)

{printf(“\n input score of student%d:\n”,I+1);

printf(“NO.:”);

scanf(“%s”,stu[i].num);

printf(“name:”);

scanf(“%s”,stu[i].name);

sum=0;

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

{printf(“score %d :”j+1);

scanf(“%d”,&stu[i].score[j]);

sum+=stu[i].score[j];

}

stu[i].ave=sum/3.0

}

fp=fopen(“stud”,”w”);

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

if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)

printf(“File write error\n”);

fclose(fp);

fp=fopen(“stud”,”r”);

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

{fread(&stu[i],sizeof(struct student),1,fp);

printf(“%s,%s,%d,%d,%d,%6.2f\n”,stu[i].num,stu[i].name,stu[i].score[0], stu[i].score[1], stu[i].score[2] ,stu[i].ave);

}

}

13.7将上题stud文件中的学生数据按平均分进行排序处理,并将已排序的学生数据存入一个新文件stu-sort中。

解:

#include <stdio.h>

#define N 10

struct student

{char num[10];

char name[8];

int score[3];

float ave;

}st[N],temp;

main()

{

FILE *fp;

Int I,j,n;

If((fp=fopen(“stud”,”r”))==NULL)

{printf(“can not open the file”);

exit(0);

}

printf(“\n file ‘stud’:”);

for(I=0;fread(&st[i],sizef(struct student),1,fp)!=0;I++)

{printf(“\n%8s%8s”,st[i].num,,st[i].name);

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

printf(“%8d”,st[i].score[j]);

printf(“%10.f”,st[i].ave);

fclose(fp);

n=I;

for(I=0;I<n;I++)

for(j=I+1;j<n;j++)

if(st[i].ave<st[j].ave)

{temp=st[i];

st[i]=st[j];

st[j]=temp;

}

printf(“\nnow:”);

fp=fopen(“stu-sort”,”w”);

for(I=0;I<n;I++)

{fwrite(&st[i],sizeof(struct student),1,fp);

printf(“\n%8s%8s”,st[i].num,st[i].name);

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

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

fclose(fp);

}

13.8将上题以排序的学生成绩文件进行插入处理。插入一个学生的3门课成绩,程序先计算新插入学生的平均成绩,然后将它按平均成绩高低顺序插入,插入后建立一个新文件。

解:#include <stdio.h>

struct student

{char num[10];

char name[8];

int score[3];

float ave;

}st[10],s;

main()

{FILE *fp, * fp1 ;

int I,j,t,n;

printf(“\n NO.:”);

scanf(“%s”,s.num);

printf(“name:”);

scanf(“%s”,s.name);

printf(“score1,score2,score3:”);

scanf(“%d,%d,%d”,&s. score[0], &s. score[1], &s. score[2]);

s.ave=(s.score[0]+s.score[1]+s.score[2])/3.0;

if((fp=fopen(“stu_sort”,”r”))==NULL)

{printf(“can not open file.”);

exit(0);

}

printf(“original data:\n”);

for(I=0;fread(&st[i],sizeof(struct student),1,fp)!=0;I++)

{printf(“\n%8s%8s”,st[i].num,st[i].name);

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

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

n=I;

for(t=0;st[t].ave>s.ave&&t<n;t++);

printf(“\nnow:\n”);

fp1=fopen(“sort1.dat”,”w”);

for(I=p;j<t;I++)

{fwrite(&st[i],sizeof(stuct student),1,fp1);

print(“\n%8s%8s”,st[i],num,st[i].name);

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

ptintf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

fwrite(&s,sizeof(struct student),1,fp1);

printf(“\n%8s%7s%7d%7d%7d%10.2f”,s.num,s.name,s.score[0],s.score[1],s.score[2],s.ave);

for(I=t;I<n;I++)

{fwrite(&st[i],sizeof(struct student),1,fp1);

printf(“\n %8s%8s”,st[i].num,st[i].name);

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

printf(“%8d”,st[i].score[j]);

printf(“10.2f”,st[i].ave);

fclose(fp);

fclose(fp1);

}

13.9上题结果仍存入原有的stu_sort文件而不另建立新文件。

解: #include<stdio.h>

struct student

{char num[10];

char name[8];

int score[3];

float ave;

}st[10],s;

main()

{FILE *fp, *fp1;

int I ,j,t,n;

printf(“\nNO.:”);

scanf(“%s’,s.num);

printf(“name:”);

scanf(“%s’,s.name);

printf(“score1,score2,score3:”);

scanf(“%d%d%d”,&s.score[0]+&s.score[1]+&s.score[1], &s.score[2]);

s.ave=( s.score[0]+ s.score[1]+ s.score[2])/3.0;

if((fp=fopen(“stu=sort”,”r”))==NULL)

{printf(“can not open the file.”);

exit(0);

}

printf(“original data:\n”);

for(I=0;fread(&st[i],sizeof(struct student),1,fp)!=0;I++)

{printf(“\n%8s%8s”,st[i].num,st[i].name);

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

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

fclose(fp);

n=I;

for(t=0;st[t].ave>s.ave+&&t<n;t++);

ptintf(“\nnow:\n”);

fp=fopen(“stu_sort”,”w”);

for(I=0;I<t;I++)

{fwrite(&st[i],sizeof(struct student),1,fp);

printf(“\n%9s%8s%8d%8d%8d%10.2f”,s.num,s.name,s.score[0],s.score[1] s.score[2] s.ave);

for(I=t;I<n;I++)

{fwrit(&sr[i],sizeof(struct srudent),1,fp);

printf(“\n %8s%8s”,st[i].num,st[i].name);

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

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

fclose(fp);

}

13.10 有一磁盘文件emploee,内存放职工的数据。每个职工的数据包括:职工姓名、职工号、性别、年龄、住址、工资、健康状况、文化程度。要求将职工名和工资的信息单独抽出来另建一个简明的职工工资文件。

解:#include<stdio.h>

struct emploee

{char num[6];

char name[10];

char sex[2];

int age;

char addr[20];

int salary;

char health[8];

char class[10];

}en[10];

struct emp

{char name[10];

int salary;

}em-case[10];

main()

{FILE *fp1, *fp2;

int I,j;

if ((fp1=fopen(“emploee”,”r”))==NULL)

{printf(“can not open the file.”);

exit(0);

}

printf(“\n NO. name sex age addr salary health class\n”);

for(I=0;fread(&em[i],sizeof(struct emploee),1,fp1)!=p;I++)

{printf(“\n%4s%8s%4s%6s%10s%6s%10s%8s”,em[i].num,em[i].name,em[i].sex, em[i].age, em[i].addr, em[i].salary, em[i].health, em[i].class);

strcpy(em_case[i].name, em[i].name);

em_case[i].salary=en[i].salary;

}

printf(“\n\n*****************************************”);

if((fp2=fopen(“emp_salary”,”wb”))==NULL)

{printf(“can not open the file.”);

exit(0);}

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

{if(fwrite(&en_case[j],sizeof(struct emp),1,fp2)!=1)

printf(“error!”);

printf(“\n %12s%10d”,em_case[j].name,em_case[j].salary);

}

printf(“\n*******************************************”);

fclose(fp1);

fclose(fp2);

}

13.11从上题的“职工工资文件”中删区一个职工的数据,再存回原文件。

解:#incude <stdio.h>

#incude <string.h>

struct emploee

{char name[10];

int salary;

}emp[20];

main()

{FILE *fp;

int I,j,n,flag;

char name[10];

int salary;

if((fp=fopen(“emp_salary”,”rb”))==NULL)

{printf(“can not open file.”);

exit(0);

}

printf(“\n original data:”);

for(I=0;fead(&emp[i],sizeof(struct emploee),1,fp)!=0;I++)

printf(“\n %8s %7d”,emp[i].name,emp[i].salary);

fclose(fp);

n=I;

printf(“\n input name deleted:”);

scanf(“%s”,name);

for(flag=1,I=0;flag&&I<n;I++)

{if(strcmp(name,emp[i].name)==0)

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

{strcmp(name,emp[i].name)==0

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

{strcpy(emp[j].name,emp[j+1].name);

emp[j].salary=emp[j+1].salary;

}

flag=0;

}

}

if(!flag)

n=n-1;

else

printf(“\n Now,the content of file:\n”);

fp=fopen(“emp-dalary”,”wb”);

for(I=p;I<n;I++)

fwrite(&emp[i],sizeof(struct emploee),1,fp);

fclose(fp);

fp=fopen(“emp_salary”,”r”);

for(I=0;fread(&emp[i],sezeof(struct emploee),1,fp)!=0;I++)

printf(“\n%8s%7d”,emp[i].name,emp[i].salary);

fclose(fp);

}

13.12 从键盘输入若干行字符(每行长度不等),输入后把它们存储到一磁盘文件中。再从该文件中读入这些数据,将其中小写字母转换成大写字母后在显示屏上输出。

解: #include<stdio.h>

main()

{int I,flag;

char str[80],c;

FILE *fp;

Fp=fopen(“text”,”w”);

Flag=1;

While(flag==1)

{printf(“\n Input string:\n”);

ges(str);

fprintf(fp,”%s”,str);

printf(“\nContinue?”);

c=getchar();

if((c==’N’)||(c==’n’))

flag=0;

getchar();

}

fcolse()fp;

fp=fopen(“text”,”r”);

while(fscanf(fp,”%s”,str)!=EOF)

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

if((str[i]>=’a’)&& (str[i]<=’z’))

str[i]-=32;

printf(“\n%s\n”,str);

}

fclose(fp);

}

小朋友,你也太懒了吧。把题目贴出来呀,难道那个还要去翻书给你解答呀。


看潭浩强的书可以学会C语言吗?
C语言当然是编程的基础语言,许多大型的软件都是用C语言编写成的,比如:matlab、microsoft visual c++6.0 等。谭浩强编写的《C程序设计(第三版)》堪称经典之作,深入浅出,适合初学者及广大C语言爱好者。只要你认真去学,学不会都难啊 ^_^ ...

谭浩强c语言的最新版本现在是第几版,还有那些版本都有什么区别?(详细...
谭浩强的书介绍的编程软件是TC,虽然已经落伍了,但是现在用的VC6.0和TC差不多,而且很容易学。我觉得谭浩强的书不错,毕竟是清华大学出版社出的嘛!他的书在经过几版之后,错误率较少,而且讲解详细,易懂,很适合自学者。这本书在中国很畅销,也受到了许多大学的认可,包括我的大学也在用它。综...

...推荐潭浩强的《C语言程序设计》但是,不知道第二版好还是第三版...
当然是第三版,因为新版会改进旧版的一些不适合之处,还会加入最新的知识。我们学的也是这本书,初学者贵在坚持和动手

对于C语言程序设计,买哪个版本作者的书学习最好?
学C语言C语言程序设计(第三版) 清华大学出版社比较好 是谭浩强编的 他出了很多本计算机的著作,特点是他编的书读者容易理解 我用的也是这个课本 挺好的~~平常习题就是书上的 有兴趣也可以自己在网上搜索一些C语言的经典习题来做 课件是老师的课件挺详细 可惜不能拷下来 要不可以给你看...我觉得...

C语言是一个好东西啊!!!想让大虾们给我这个小子推荐一本学习C的书籍...
《C语言程序设计》第三版 潭浩强《C++ Primer 中文版》《C++语言的设计和演化》 机械工业出版社 《汤姆斯旺的C++编程秘诀》 《C语言编程宝典之一》 除此之外,还有一个专家提供的书目,由浅入深,很有层次,写出来以供参考: C++\/OPP\/OOD系列: 层级一:语法\/语意(C++) [Lippman2000] Essential C++ Essential ...

学完潭浩强的《C++程序程序》后,想深入C++学习,学谁编写的教材好_百度...
(一)语言入门:《C++ Primer》最新版本:第三版(第四版国外已上架,国内一些网上书店也在预订中)适合有丰富C经验,缺乏C++经验的。不过我个人一直认为此书带着过于强烈的C语言的痕迹,对于C++的学习未必是好事。《The C++ Programming Language》\/《C++程序设计语言》最新版本:第三版特别版 简称TC++...

谭浩强 C语言程序设计 一书有何缺点
强哥的这本书很适合初学!浅显易懂,但这是它的优点,也是它的缺点。介绍的知识都很基础,对于一个编程一点都不会的人是很适合的,但如果你有一定基础的话,就没必要看强哥的了,因为它讲的没侧重点,许多c中的功能都叙述不全,不适合进阶学习。总的来说就是如果你是新手,看看他的书没问题,如果...

唐浩强的C语言程序设计和C程序设计有什么不同?
我们上个学期学的是C程序设计,这个学期学的是C语言程序设计,老师说虽然看上去差不多,其实是两门不同的课,C程序设计基本上就是老师讲一点自己写一点,而C语言程序设计就是老师教你几个函数,要自己去设计,比如老师布置一个作业,设计个通讯录,然后就叫你自己去做,这就是设计啊!

潭浩强C语言程序设计及其其相关资料到,有的分享一下
建议你买本书,书比网上的电子版教程好的多,如计算机届超级权威教授 谭浩强 老先生写的《C语言程序设计(第三版)》,全国发行了700万册,可以说是学C语言的人必看的书,我们大学就用这本书,很适合自学,通俗易懂 建议你学习其它计算机知识时也看他的书,他出的书很多,涵盖面广,每一本都很...

C语言程序设计 谭浩强 为什么很多人说他害人
谭浩强的书真的是只适合二级的,基本上适合所有专业的人,如果你是计算机的,那他这本书真的只算是入门的。其实一门语言并不是很重要,重要的是算法,语言是死的,算法是有灵魂的

开福区15379831097: c语言程序设计课后答案及上机指导 谭浩强第三版 -
羽矿磺胺: (第一题)#include <stdio.h> void main() { int gy(int m, int n); int x,y,max, min; printf("请输入两个大于0的正整数,以空格或者回车间隔:\n"); scanf("%d%d",&x,&y); while(x<1 || y<1) { printf("输入数据不正确,请重新输入.\n"); printf(...

开福区15379831097: 谁有谭浩强的C程序设计第三版课后习题答案 -
羽矿磺胺: C程序设计(第三版)[谭浩强著]课后题答案!!!(2009-06-04 19:57:53)标签:教育 分类:学习 1.5请参照本章例题,编写一个C程序,输出以下信息: ************************** Very Good! ************************** 解: mian() {printf(“**********...

开福区15379831097: 谭浩强 C程序设计第三版 课后习题答案 -
羽矿磺胺: 6.7完数

开福区15379831097: 谭浩强c语言第三版答案 -
羽矿磺胺: 去百度文库里搜“c语言程序设计答案”就能找到.http://wenku.baidu.com/view/c0a48d30b90d6c85ec3ac6b2.html

开福区15379831097: C程序设计(第三版)课后习题答案 -
羽矿磺胺: 我现在做了 C程序设计(第三版)课后习题答案 中的7.7和7.8,是求魔方阵和鞍点的,剩下的我以后在做 #include<stdio.h> void main() { int i,j,m,n,p,number=0; int a[4][4]; for(i=0;i<4;i++) for(j=0;j<4;j++) scanf("%d",&a[i][j]); for(i=0;i<4;i++) {for(j=0;...

开福区15379831097: 谭浩强编著.C语言程序设计的习题答案.清华大学出版社2000年1月第一版
羽矿磺胺: c程序设计习题参考(谭浩强二.三版) 答案地址:http://www.khdaw.com/bbs/thread-80-1-1.html C程序设计之谭浩强版 答案地址:http://www.khdaw.com/bbs/thread-47-1-4.html C语言第三版课后答案(文本文件类型) http://www.khdaw.com/bbs/...

开福区15379831097: 谁有C程序设计第三版谭浩强的课后答案txt格式的
羽矿磺胺: http://hi.baidu.com/xq890322/blog/item/7cbb0bd69696982a06088b44.html这是一至六章http://hi.baidu.com/xq890322/blog/item/e4eb3afd258cd61308244d44.html七至九章http://hi.baidu.com/xq890322/blog/item/431f8b0884391135e924885c.html十章http://hi.baidu.com/xq890322/blog/item/0937b9fa90cf758c9e51465c.html十一章楼主自己合成一下吧,我也给你发不过去

开福区15379831097: 【C语言中 x=a=3,6*3 x a分别等于多少】谭浩强C程序设计第三版第65页 倒数第二段说X=3整个逗号表达式的值为18 “整个逗号表达式的值为18”是什么意... -
羽矿磺胺:[答案] 答:x=3;a=3 执行过程是: a=3; x=a;(即x=3)(赋值运算“=”号,是从右到左执行的) 被忽略的是6*3(因为这只是一个算术表达式,并没有参与赋值)

开福区15379831097: c语言第三版课后答案
羽矿磺胺: http://www.taodaan.com/index.php?searchid=2237&orderby=sortid&ascdesc=desc&searchsubmit=yes自己选

开福区15379831097: c程序设计第三版课后习题答案 -
羽矿磺胺: http://ishare.iask.sina.com.cn/search.php?key=c%B3%CC%D0%F2%C9%E8%BC%C6%B5%DA%C8%FD%B0%E6+%CF%B0%CC%E2&format= 试试这个

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网