结构体变量分析

1,结构体变量的初始化

#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;
}

#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;
}

#include<stdio.h>
struct Person
{
char name[20];
int count;
}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].count++;
}

}
printf("\nResult:\n");
for(i=0;i<3;i++)
printf("%5s:%d\n",leader[i].name,leader[i].count);
return 0;
}

晚上先敲这么多,明天继续。看自己能坚持多少天。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值