结构体

 1 #include<stdio.h>
 2 struct birthday {
 3 int year,mooth,day;
 4 };
 5 struct student {
 6 int tel;
 7 char name[20];
 8 struct birthday birth;
 9 
10 };
11 
12 int main(void)
13 {struct student a[20];
14 
15 
16 int n,t,i,j;
17 
18 scanf("%d",&n);
19 for(i=0;i<n;i++){
20 printf("Input student:\n");
21 scanf("%s%d%d%d%d",a[i].name,&a[i].tel,&a[i].birth.year,&a[i].birth.mooth,&a[i].birth.day);}
22 for(i=1;i<n;i++){
23 for(j=0;j<n-i;j++){
24 if(a[j].birth.year>a[j+1].birth.year){
25 t=a[j].birth.year;
26 a[j].birth.year=a[j+1].birth.year;
27 a[j+1].birth.year=t;}}}
28 if(a[j].birth.year==a[j+1].birth.year){
29 if(a[j].birth.mooth>a[j+1].birth.mooth)
30 t=a[j].birth.mooth;
31 a[j].birth.mooth=a[j+1].birth.mooth;
32 a[j+1].birth.mooth=t;
33 printf("输出排序后的信息\n");}
34 for(i=0;i<n;i++){
35 printf("%s\t%d\t%d\t%d\t%d\n",a[i].name,a[i].tel,a[i].birth.year,a[i].birth.mooth,a[i].birth.day);}
36 return 0;
37 }
 1 /*按等级统计学生成绩*/
 2 #include<stdio.h>
 3 #include<string.h>
 4 
 5 int set_grade(struct student students[10],int n);
 6 
 7 struct student{
 8 int num;
 9 char name[10]; 
10 double score; 
11 char grade; 
12 };
13 int main()
14 {
15 int n,i,count;
16 
17 printf("输入统计学生个数:"); 
18 scanf("%d",&n);
19 struct student students[10];
20 for(i=0;i<n;i++){
21 printf("姓名:");
22 scanf("%s",&students[i].name);
23 printf("学号:");
24 scanf("%d",&students[i].num);
25 printf("成绩:");
26 scanf("%lf",&students[i].score);
27 
28 count=set_grade(students,n); 
29 }
30 for(i=0;i<n;i++){
31 
32 printf("学号:%d 姓名:%s 等级:%c\n",students[i].num,students[i].name,students[i].grade); 
33 }
34 
35 printf("成绩不及格人数为:%d\n",count); 
36 return 0;
37 }
38 int set_grade(struct student students[10],int n) 
39 {
40 int i,count=0;
41 for(i=0;i<n;i++)
42 
43 {
44 if(students[i].score<60){
45 students[i].grade='D';
46 
47 count++;
48 } 
49 else if(students[i].score<70&&students[i].score>=60){
50 students[i].grade='C';
51 }
52 else if(students[i].score<85&&students[i].score>=70){
53 students[i].grade='B';
54 }
55 else if(students[i].score<=100&&students[i].score>=85){
56 students[i].grade='A';
57 }
58 }
59 return count; 
60 }

转载于:https://www.cnblogs.com/wagb/p/yyyy.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值