C语言之结构数组图书管理
来源:互联网 发布:金属材料冲击实验数据 编辑:程序博客网 时间:2024/05/19 18:00
/*包含多本书的图书目录*/
#include<stdio.h>
#define MAXBKS 2 //定义最多容纳的图书册数struct book // 结构体名为bool
{
char title[50];
char author[50];
float value;
};
int main()
{
struct book library[MAXBKS]; //定义结构数组
int count=0;
int index;
printf("input a title\n");
printf("press[enter]at the begin to end\n");
gets(library[count].title);
while(count<MAXBKS&&library[count].title[0]!='\0')
{
printf("input author\n");
gets(library[count].author);
printf("input value\n");
scanf("%f",&library[count].value);
count++;
while(getchar()!='\n')
continue;
/*按入回车时不进入while循环,相当于某种意义上的清除回车,若没有这句话,会输入回车,然后跳出while循环*/
if(count<MAXBKS){printf("input next title\n");
gets(library[count].title);}
}
if(count>0)
{
printf("here are your books\n");
for(index=0;index<count;index++)
{
printf("%s by %s:$%.2f\n",library[index].title,library[index].author,library[index].value);
}
}
else
printf("NO\n");
return 0;
}
在看一个例子
输入4名学生的各3门成绩,然后求出每个学生的总成绩和平均成绩并打印出来
#include<stdio.h>>
struct student2
{
int number;
char name[10];
char sex;
float score[3];//3科成绩
float sum;
float ave;
};
int main()
{
int i,j;
struct student2 stu[4];//结构体数组
for(i=0;i<4;i++)
{
printf("input\n");
scanf("%d %s %c",&stu[i].number,&stu[i].name,&stu[i].sex);//注意别落了取地址符&
stu[i].sum=0;
stu[i].ave=0;
printf("input score\n");
for(j=0;j<3;j++)
{
scanf("%f",&stu[i].score[j]);
stu[i].sum+=stu[i].score[j];
}
stu[i].ave=stu[i].sum/3;
}
printf("学号 姓名 性别 语文 数学 英语 总分 均分\n");
for(i=0;i<4;i++)
{
printf("%d %s %c",stu[i].number,stu[i].name,stu[i].sex);
for(j=0;j<3;j++)
{
printf(" %.2f",stu[i].score[j]);
}
printf(" %.2f %.2f\n",stu[i].sum,stu[i].ave);
}
return 0;
}
- C语言之结构数组图书管理
- 图书管理系统c语言 结构体数组实现
- C语言图书管理系统
- 图书管理系统 C语言
- C语言图书管理系统
- 【C语言】图书管理系统
- 图书管理系统(C语言)
- C语言图书管理系统
- C语言之 数组 指针 结构体
- C语言课程设计—图书管理系统
- 图书管理系统 C 语言 源代码
- (C语言课程设计)图书管理系统
- C语言课程设计—图书管理系统
- C语言 图书管理系统设计
- C语言基础上的图书管理系统
- 图书管理系统C语言课程设计2
- 图书管理系统(C语言)
- 图书信息借阅管理系统 C语言
- xdu 1068 Clinton’s beliefs
- android进程间通信学习
- CENTOS5.5下使用Roundcube搭建 Webmail
- [sicily] 1003. hit or miss
- ofstream和ifstream详细用法
- C语言之结构数组图书管理
- 兔子-Android 项目中values-v11 values-v14
- 如何利用Spring Cloud构建起自我修复型分布式系统
- Jquery选择器
- SCOM2012升级授权License
- Bitmap结构详解
- mahout类似的开源项目
- 两个portlet之间跳转并传值
- java基础整理の网络编程两协议小结