标签:style ret higher 6.2 0.00 res scanf ddr lis
例9.1程序
#include<stdio.h> #include<stdlib.h> int main() { struct student { long int num; char name[20]; char sex; char addr[20]; } a={1,"sun",‘m‘,"123 beijing road"}; printf("NO.:%ld\n name:%s\n sex:%c\n addr:%s\n",a.num,a.name,a.sex,a.addr); return 0; }
运行结果
NO.:1 name:sun sex:m addr:123 beijing road -------------------------------- Process exited after 0.006787 seconds with return value 0 请按任意键继续. . .
例9.2
#include<stdio.h> #include<stdlib.h> int main() { struct student { long 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; }
运行结果:
1 孙 89 2 刘 90 The higher score is: 2 刘 90.00 -------------------------------- Process exited after 78.92 seconds with return value 0 请按任意键继续. . .
例9.3:
#include<stdio.h> #include<stdlib.h> #include<string.h> struct person { char name[20]; int count; }leader[3]={"li",0,"sun",0,"zhang",0}; int main() {int i,j; char leader_name[20]; for(i=0;i<=10;i++) { scanf ("%s",leader_name); for(j=0;j<3;j++) if(strcmp(leader_name,leader[j].name)==0) leader[j].count++; } printf("\n Result:\n"); for(i=0;i<3;i++) printf("%5s:%d\n",leader[i].name,leader[i].count); return 0; }
运行结果:
sun li liu sun li li liu sun li lisun li Result: li:5 sun:3 zhang:0 -------------------------------- Process exited after 2.568 seconds with return value 0 请按任意键继续. . .
例9.4:
标签:style ret higher 6.2 0.00 res scanf ddr lis
原文地址:http://www.cnblogs.com/sunyue/p/6681790.html