#include<stdio.h> int main() { struct Student { long int num; char name[20]; char sex; char addr[20]; } a={10101,"Li Lin",'M',"123 Beijing Road"}; printf("NO.:%ld\nname:%s\nsex:%c\naddress:%s\n",a.num,a.name,a.sex,a.addr); return 0; }
NO.:10101 name:Li Lin sex:M address:123 Beijing Road -------------------------------- Process exited after 0.05706 seconds with return value 0 请按任意键继续. . .
#include<stdio.h> int main() { struct Student { int num; char name[20]; float score; }student1,student2; scanf("%d%s%f",&student1.num,student1.name,&student1.score); scanf("%d%s%f",&student2.num,student2.name,&student2.score); printf("The higher score is:\n"); if(student1.score>student2.score) printf("%d %s %6.2f\n",student1.num,student1.name,student1.score); else if(student1.score<student2.score) printf("%d %s %6.2f\n",student2.num,student2.name,student2.score); else { printf("%d %s %6.2f\n",student1.num,student1.name,student1.score); printf("%d %s %6.2f\n",student2.num,student2.name,student2.score); } return 0; }
22,222,2222 22,222,2222 The higher score is: 22 ,222,2222 22.00 -------------------------------- Process exited after 7.463 seconds with return value 0 请按任意键继续. . .
#include<string.h> #include<stdio.h> struct Person { char name[20]; int conut; } leader[3]={"li",0,"zhang",0,"sun",0}; int main() { int i,j; char leader_name[20]; for(i=1;i<=10;i++) { scanf("%s",leader_name); for(j=0;j<3;j++) { if(strcmp(leader_name,leader[j].name)==0) leader[j].conut ++; } } printf("\nResult:\n"); for(i=0;i<3;i++) printf("%5s:%d\n",leader[i].name,leader[i].conut ); return 0; }
li li li li li zhang li zhang li zhang Result: li:7 zhang:3 sun:0 -------------------------------- Process exited after 17.44 seconds with return value 0 请按任意键继续. . .
#include<stdio.h> struct Student { int num; char name[20]; float score; }; int main() { struct Student stu[5]={{11111,"yi",11},{22222,"er",22},{33333,"san",33},{44444,"si",44},{55555,"wu",55}}; struct Student temp; const int n=5; int i,j,k; printf("The order is:\n"); for(i=0;i<n-1;i++) { k=i; if(stu[j].score>stu[k].score) k=j; temp=stu[k]; stu[k]=stu[i]; stu[i]=temp; } for(i=0;i<n;i++) printf("%6d %8s %6.2f\n",stu[i].num,stu[i].name,stu[i].score); printf("\n"); return 0; }
The order is: 11111 yi 11.00 22222 er 22.00 33333 san 33.00 44444 si 44.00 55555 wu 55.00 -------------------------------- Process exited after 0.06133 seconds with return value 0 请按任意键继续. . .
#include<stdio.h> #include<string.h> int main() { struct student { long num; char name[20]; char sex; float score; }; struct student stu_1={10101,"Li Lin",'M',89.5}; struct student *p; p=&stu_1; printf("%d,%s,%c,%f\n",stu_1.num,stu_1.name,stu_1.sex,stu_1.score); printf("%d,%s,%c,%f\n",(*p).num,(*p).name,stu_1.sex,(*p).score); return 0; }
10101,Li Lin,M,89.500000 10101,Li Lin,M,89.500000 -------------------------------- Process exited after 0.06501 seconds with return value 0 请按任意键继续. . .
#include<stdio.h> struct Student { int num; char name[20]; char sex; int age; }; struct Student stu[3]={{1,"yi",'M',11},{2,"er",'M',22},{3,"san",'F',33}}; int main() { struct Student *p; printf("No. name sex age\n"); for(p=stu;p<stu+3;p++) printf("%d,%s,%c,%d\n",p->num,p->name,p->sex,p->age); return 0; }
No. name sex age 1,yi,M,11 2,er,M,22 3,san,F,33 -------------------------------- Process exited after 0.04645 seconds with return value 0 请按任意键继续. . .
#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]); }
请输入各学生的信息:学号、姓名、三门学科的成绩: 1 一 11 111 1111 2 二 22 222 2222 3 三 33 333 3333 成绩最高的学生是: 学号:3 姓名:三 三门课成绩: 33.0,333.0,3333.0平均成绩: 0.00 -------------------------------- Process exited after 42.87 seconds with return value 0 请按任意键继续. . .
总结
1.有些不熟悉的地方加深了印象
2.打字速度变快了
3.不要马虎