加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

结构体1

发布时间:2020-12-14 04:43:18 所属栏目:大数据 来源:网络整理
导读:1 /* 通讯录排序 */ 2 #includestdio.h 3 struct birthday { 4 int year,mooth,day; 5 }; 6 struct student { 7 int tel; 8 char name[ 20 ]; 9 struct birthday birth; 10 11 }; 12 13 int main( void ) 14 { struct student a[ 20 ]; 15 16 17 int n,t,i,j
 1 /*通讯录排序*/
 2 #include<stdio.h>
 3 struct birthday {
 4 int year,mooth,day;
 5 };
 6 struct student {
 7 int tel;
 8 char name[20];
 9 struct birthday birth;
10 
11 };
12 
13 int main(void)
14 {struct student a[20];
15 
16 
17 int n,t,i,j;
18 
19 scanf("%d",&n);
20 for(i=0;i<n;i++){
21 printf("Input student:n");
22 scanf("%s%d%d%d%d",a[i].name,&a[i].tel,&a[i].birth.year,&a[i].birth.mooth,&a[i].birth.day);}
23 for(i=1;i<n;i++){
24 for(j=0;j<n-i;j++){
25 if(a[j].birth.year>a[j+1].birth.year){
26 t=a[j].birth.year;
27 a[j].birth.year=a[j+1].birth.year;
28 a[j+1].birth.year=t;}}}
29 if(a[j].birth.year==a[j+1].birth.year){
30 if(a[j].birth.mooth>a[j+1].birth.mooth)
31 t=a[j].birth.mooth;
32 a[j].birth.mooth=a[j+1].birth.mooth;
33 a[j+1].birth.mooth=t;
34 printf("输出排序后的信息n");}
35 for(i=0;i<n;i++){
36 printf("%st%dt%dt%dt%dn",a[i].tel,a[i].birth.year,a[i].birth.mooth,a[i].birth.day);}
37 return 0;
38 }
 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,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 等级:%cn",students[i].num,students[i].name,students[i].grade); 
33 }
34 
35 printf("成绩不及格人数为:%dn",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 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读