云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > C语言第8章习题及答案

C语言第8章习题及答案

  • 62 次阅读
  • 3 次下载
  • 2025/7/14 8:56:18

第八章

8.1 用一个数组存放图书信息,每本书是一个结构,包括下列几项信息:书名、作者、出版年月、借出否,试写出描述这些信息的说明,并编写一个程序,读入若干本书的信息,然后打印出以上信息。#include

typedef struct {

char Name[20]; char Author[20]; int Date_Year; int Date_Month; int loaned; } BOOK;

#define N 10

void main() {

BOOK books[N]; int i;

for (i=0;i

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

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

printf(\ scanf(\

printf(\ scanf(\

printf(\ scanf(\ }

for (i=0;i

printf(\%s, Author: %s, Publishing:%d-%d, Status:%d\\n\books[i].Name, books[i].Author, books[i].Date_Year, books[i].Date_Month, books[i].loaned); } }

8.3 编写一个函数,统计并打印所输入的正文中的各个英文单词出现的次数,并按次数的递减顺序输出。#include #include

typedef struct {

char s[20];

int count; } WORD;

#define N 100

WORD words[N]={0};

int word_count=0;

int IsSeparator(char c) {

if ( 'A'<=c && c<='Z' || 'a'<=c && c<='z' || '0'<=c && c<='9' || '_'==c || '-'==c) return 0; else

return 1; }

void AddWord(char *s) {

int i,found=0; char ss[20];

for(i=0;*s && !IsSeparator(*s);s++,i++) ss[i]=*s; ss[i]=0;

for (i=0;i

if (strcmp(ss, words[i].s)==0) {

found=1; break; }

if (found==0) {

words[word_count].count=1;

strcpy(words[word_count].s, ss); word_count++; } else {

words[i].count++; } }

void func(char *s)

{

int i,j,t; char c,lc; WORD temp;

lc=*s;

if (!IsSeparator(lc)) AddWord(s);

for (i=1;c=*(s+i);i++) {

if (!IsSeparator(c) && IsSeparator(lc)) AddWord(s+i); lc=c; }

for (i=0;i

t=i;

for(j=i+1;j

if (words[t].count

if (i!=t) {

temp=words[t]; words[t]=words[i]; words[i]=temp; } }

for (i=0;i

printf(\ } }

void main() {

char *s=\program has a primary main function that must be named main\

func(s); }

8.5 有10个学生,每个学生的数据包括学号、姓名和三门课的成绩。用键盘输入10个学生的数据,要求打印出每个学生三门课的平均成绩,以及最高分的学生的数据(学号、姓名、

三门课的成绩和平均分数)。 #include #include

typedef struct {

char name[20]; char sno[20]; int score_1; int score_2; int score_3;

double score_all; } STUDENT;

#define N 10

STUDENT students[N]={0};

void main() {

int i,max;

for (i=0;i

printf(\ scanf(\

printf(\ scanf(\

printf(\ scanf(\

printf(\ scanf(\

printf(\ scanf(\

students[i].score_all=students[i].score_1+students[i].score_2+students[i].score_3; }

max=0;

for(i=0;i

printf(\%s %d %d %d %lf \\n\students[i].sno, students[i].score_1, students[i].score_2, students[i].score_3, students[i].score_all/3);

if (students[max].score_all

搜索更多关于: C语言第8章习题及答案 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

第八章 8.1 用一个数组存放图书信息,每本书是一个结构,包括下列几项信息:书名、作者、出版年月、借出否,试写出描述这些信息的说明,并编写一个程序,读入若干本书的信息,然后打印出以上信息。#include typedef struct { char Name[20]; char Author[20]; int Date_Year; int Date_Month; int loaned; } BOOK; #define N 10 void main() { BOOK books[N]; int i; for (i=0;i

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com