//P19
#include <stdio.h>
struct date
{
int year;
int month;
int day;
};
struct student
{
char name[10];
char sex[5];
int age;
date birthday;
};
void main()
{
student ming = {"小明","男",18,{1984,4,14}};
printf("%s %s %d %d %d %d\n",ming.name,ming.sex,ming.age,ming.birthday.year,ming.birthday.month,ming.birthday.day);
scanf("%d",&ming.age);
printf("%s %s %d %d %d %d\n",ming.name,ming.sex,ming.age,ming.birthday.year,ming.birthday.month,ming.birthday.day);
}
//P29 Y1
#include <stdio.h>
struct Node
{
int nA;
int nB;
int nC;
};Node node = {0,0,0}; //node要定义成全局变量
void fund()
{
printf("nA=");
scanf("%d",&node.nA);
printf("nB=");
scanf("%d",&node.nB);
printf("nC=");
scanf("%d",&node.nC);
}
void main()
{
fund();
printf("%d %d %d\n",node.nA,node.nB,node.nC);
}
//计算天数
#include <stdio.h>
struct Date
{
int year;
int month;
int day;
};
void chang(Date input)
{
int month = 0,day =0;
printf("请输入日期(月.日):\n");
scanf("%d.%d",&input.month,&input.day);
int alldays = 0;
switch(input.month)
{
case 1:alldays = day;break;
case 2:alldays = 31 +day;break;
case 3:alldays = 31 +28+day;break;
case 4:alldays = 31 +28+31+day;break;
case 5:alldays = 31 +28+31+30+day;break;
case 6:alldays = 31 +28+31+30+31+day;break;
case 7:alldays = 31 +28+31+30+31+30+day;break;
case 8:alldays = 31 +28+31+30+31+30+31+day;break;
case 9:alldays = 31 +28+31+30+31+30+31+30+day;break;
case 10:alldays = 31 +28+31+30+31+30+31+30+31+day;break;
case 11:alldays = 31 +28+31+30+31+30+31+30+31+30+day;break;
case 12:alldays = 334 +day;break;
}
printf("第%d天\n",alldays);
}
void main()
{
struct Date input = {0,0,0};
chang(input);
}
//输入成绩输出列表和统计
#include <stdio.h>
struct marks
{
int a_mark;
int b_mark;
int c_mark;
};
struct students
{
char ID[4];
char name[100];
marks input;
}mDate[4] = {{"001","大杜",{0,0,0}},{"002","大王",{0,0,0}},{"003","大公",{0,0,0}},{"004","大姜",{0,0,0}}};
void main()
{
printf("请输入大杜的成绩:\n");
scanf("%d%d%d",&mDate[0].input.a_mark,&mDate[0].input.b_mark,&mDate[0].input.c_mark);
printf("请输入大王的成绩:\n");
scanf("%d%d%d",&mDate[1].input.a_mark,&mDate[1].input.b_mark,&mDate[1].input.c_mark);
printf("请输入大公的成绩:\n");
scanf("%d%d%d",&mDate[2].input.a_mark,&mDate[2].input.b_mark,&mDate[2].input.c_mark);
printf("请输入大姜的成绩:\n");
scanf("%d%d%d",&mDate[3].input.a_mark,&mDate[3].input.b_mark,&mDate[3].input.c_mark);
int n0 = (mDate[0].input.a_mark+mDate[0].input.b_mark+mDate[0].input.c_mark)/3;
int n1 = (mDate[1].input.a_mark+mDate[1].input.b_mark+mDate[1].input.c_mark)/3;
int n2 = (mDate[2].input.a_mark+mDate[2].input.b_mark+mDate[2].input.c_mark)/3;
int n3 = (mDate[3].input.a_mark+mDate[3].input.b_mark+mDate[3].input.c_mark)/3;
printf("学号\t 姓名\t 科目成绩\t 平均分数\n");
printf("-------------------------------------------------------\n");
printf("%s\t %s\t %d, %d, %d\t\ %d\n",mDate[0].ID,mDate[0].name,mDate[0].input,n0);
printf("%s\t %s\t %d, %d, %d\t\ %d\n",mDate[1].ID,mDate[1].name,mDate[1].input,n1);
printf("%s\t %s\t %d, %d, %d\t\ %d\n",mDate[2].ID,mDate[2].name,mDate[2].input,n2);
printf("%s\t %s\t %d, %d, %d\t\ %d\n",mDate[3].ID,mDate[3].name,mDate[3].input,n3);
int markdata[4] = {n0,n1,n2,n3};
int temp_mark = 0;
for(int i = 0;i < 3;i++)
{
if(markdata[i]>markdata[i+1])
{
int temp = markdata[i];
markdata[i] = markdata[i+1];
markdata[i+1] = temp;
}
}//冒泡一次,只求出最好的成绩
temp_mark = markdata[3];
printf("成绩最好的家伙是:\n");
for(int j = 0;j < 4;j++)
{
if((mDate[j].input.a_mark+mDate[j].input.b_mark+mDate[j].input.c_mark)/3 == temp_mark)
{
printf("%s\t %s\t %d, %d, %d\t\ %d\n",mDate[j].ID,mDate[j].name,mDate[j].input,temp_mark);
break;
}
}
}