标签:ted address ++ efi str max font process sharp
9.1
#include<stdio.h> struct Student { long int num; char name[10]; char sex[3]; char address[20]; } stu={1001,"张三","男","哈尔滨"}; int main() { printf("学号=%d\n姓名=%s\n性别=%s\n地址=%s\n",stu.num ,stu.name ,stu.sex ,stu.address ); }
运行结果:
学号=1001 姓名=张三 性别=男 地址=哈尔滨 -------------------------------- Process exited after 0.01108 seconds with return value 0 请按任意键继续. . .
9.2
#include<stdio.h> #include<string.h> struct Student { int num; char name[10]; float score; } ; int main() { struct Student student1,student2; printf("请输入两位同学的信息:\n"); scanf("%d %s %f",&student1.num ,student1.name ,&student1.score ); scanf("%d %s %f",&student2.num ,student2.name ,&student2.score ); printf("成绩最高的学生信息:\n"); if(student1.score >student2.score ) { printf("num=%d\nname=%s\nscore=%f\n",student1.num ,student1.name ,student1.score ); } if(student1.score <student2.score ) { printf("num=%d\nname=%s\nscore=%f\n",student2.num ,student2.name ,student2.score ); } }
运行结果:
请输入两位同学的信息: 1001 张三 69 1002 李四 78 成绩最高的学生信息: num=1002 name=李四 score=78.000000 -------------------------------- Process exited after 16.38 seconds with return value 0 请按任意键继续. . .
9.3
#include<stdio.h> #include<string.h> struct Person { char name[20]; int count; } ; int main() { struct Person person[3]={"张三",0,"李四",0,"王五",0}; int i,j; char name[10]; for(i=0;i<5;i++) { printf("请输入您选 的候选人:"); scanf("%s",name); for(j=0;j<3;j++) { if(strcmp(name,person[j].name )==0) person[j].count ++; } } printf("统计成功!\n"); for(i=0;i<3;i++) { printf("%s:%d\n",person[i].name ,person[i].count ); } }
运行结果:
请输入您选择的候选人:张三 请输入您选择的候选人:李四 请输入您选择的候选人:王五 请输入您选择的候选人:王五 请输入您选择的候选人:12 统计成功! 张三:1 李四:1 王五:2 -------------------------------- Process exited after 19.8 seconds with return value 0 请按任意键继续. . .
9.4
#include<stdio.h> #include<string.h> struct STD { int number; char name[10]; int score; }; int main() { struct STD stu[5]={{1001,"张三",65},{1002,"李四",75},{1003,"王五",67},{1004,"马六",87},{1005,"羊七",61}},temp; struct STD *p; p=stu; int i,j; for(j=0;j<4;j++) { for(i=0;i<4;i++,p++) { if(stu[i].score <stu[i+1].score) { temp=stu[i] ; stu[i] =stu[i+1] ; stu[i+1]=temp; } } } for(i=0;i<5;i++) { printf("%d\t%s\t%d\n",stu[i].number ,stu[i].name ,stu[i].score ); } }
运行结果:
1004 马六 87 1002 李四 75 1003 王五 67 1001 张三 65 1005 羊七 61 -------------------------------- Process exited after 0.007641 seconds with return value 13 请按任意键继续. . .
9.5
#include<stdio.h> #include<string.h> struct STD { int num; char name[20]; char sex[3]; int score; }; int main() { struct STD stu,*p; p=&stu; stu.num =1001; strcpy(stu.name ,"张三"); strcpy(stu.sex ,"男"); stu.score =76; printf("学号=%d\n姓名=%s\n性别=%s\n成绩=%d\n",stu.num ,stu.name ,stu.sex ,stu.score ); printf("学号=%d\n姓名=%s\n性别=%s\n成绩=%d\n",p->num ,p->name ,p->sex ,p->score ); }
运行结果:
学号=1001 姓名=张三 性别=男 成绩=76 学号=1001 姓名=张三 性别=男 成绩=76 -------------------------------- Process exited after 0.007976 seconds with return value 36 请按任意键继续. . .
9.6
#include<stdio.h> #include<string.h> struct STD { int num; char name[20]; char sex[3]; int score; }; int main() { struct STD stu[3]={{1001,"张三","男",68},{1002,"小红","女",76},{1003,"小明","男",79}},*p; p=stu; printf("学号\t姓名\t性别\t成绩\n"); for(;p<stu+3;p++) { printf("%d\t%s\t%s\t%d\n",p->num ,p->name ,p->sex ,p->score ); } }
运行结果:
学号 姓名 性别 成绩 1001 张三 男 68 1002 小红 女 76 1003 小明 男 79 -------------------------------- Process exited after 0.01121 seconds with return value 10485312 请按任意键继续. . .
9.7
#include <stdio.h> #define N 3 struct Student { int num; char name[20]; float score[3]; float aver; }; int main() { void input(struct Student stu[]); struct Student max(struct Student stu[]); void print(struct Student stu); struct Student stu[N],*p=stu; input(p); print(max(p)); return 0; } void input(struct Student stu[]) { int i; printf("请输入各学生的信息:学号、姓名、三门学科的成绩:\n"); for(i=0;i<N;i++) { scanf("%d %s %f %f %f",&stu[i].num,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]); stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0; } } struct Student max(struct Student stu[]) { int i,m=0; for(i=0;i<N;i++) if(stu[i].aver>stu[m].aver)m=i; return stu[m]; } void print(struct Student stud) { printf("\n成绩最高的学生是:\n"); printf("学号:%d\n姓名:%s\n三门课成绩:%5.1f,%5.1f,%5.1f平均成绩:%6.2f\n",stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2]); }
运行结果:
请输入各学生的信息:学号、姓名、三门学科的成绩:
一 11 111 1111
二 22 222 2222
三 33 333 3333
成绩最高的学生是:
学号:3
姓名:三
三门课成绩: 33.0,333.0,3333.0平均成绩: 0.00
--------------------------------
Process exited after 42.87 seconds with return value 0
请按任意键继续. . .
总结:这次作业主要目的是为了能够巩固一下书上的例题,感觉还是有些欠缺的地方,以后会多加练习。
标签:ted address ++ efi str max font process sharp
原文地址:http://www.cnblogs.com/cccyb/p/6690855.html