|
20鱼币
程序运行截图如下:
代码如下:
#include<stdio.h>
#define NUM 1
struct
{
char name[20];
char sex[20];
int year;
int zk;
union
{
struct
{
char marriedtime[20];
char spousename[20];
int child;
}havemarried;
struct
{
char divorcetime[20];
int child;
}divorce;
}settle;
}person[NUM];
int main(void)
{
int i;
for(i=0;i<NUM;i++)
{
printf("Please enter personnel information:\n");
scanf("%s %s %d %d",&person[i].name,&person[i].sex,&person[i].year,&person[i].zk);
if(person[i].zk==1)
{
printf("检测为已婚,请输入结婚时间,配偶姓名,子女数量:\n");
scanf("%s %s %d",&person[i].settle.havemarried.marriedtime,
&person[i].settle.havemarried.spousename,
&person[i].settle.havemarried.child);
}
else if(person[i].zk==2)
{
printf("检测为离婚,请输入离婚时间,以及子女数量:\n");
scanf("%s %d",&person[i].settle.divorce.divorcetime,
&person[i].settle.divorce.child);
}
}
printf("\n");
printf("姓名\t性别\t年龄\t婚姻状况\n");
for(i=0;i<NUM;i++);
{
if(person[i].zk==1)
printf("%s\t%s\t%d\t结婚日期: %s 配偶姓名:%s 子女数量:%d\n",&person[i].name,&person[i].sex,
&person[i].year,&person[i].settle.havemarried.marriedtime,&person[i].settle.havemarried.spousename,&person[i].settle.havemarried.child);
else if(person[i].zk==2)
printf("%s\t%s\t%d\t离婚日期:%s \t\t子女数量:%d\n",
&person[i].name,&person[i].sex,&person[i].year,&person[i].settle.divorce.divorcetime,&person[i].settle.divorce.child);
else
printf("%s\t%s\t%d\t单身yyds!\n",person[i].name,person[i].sex,person[i].year);
}
return 0;
}
- #include <stdio.h>
- #define NUM 1
- struct
- {
- char name[20];
- char sex[20];
- int year;
- int zk;
- union
- {
- struct
- {
- char marriedtime[20];
- char spousename[20];
- int child;
- }havemarried;
- struct
- {
- char divorcetime[20];
- int child;
- }divorce;
- }settle;
- } person[NUM];
- int main(void)
- {
- int i;
- for(i=0;i<NUM;i++)
- {
- printf("Please enter personnel information:\n");
- //scanf("%s %s %d %d",&person.name,&person.sex,&person.year,&person.zk);
- scanf("%s %s %d %d",person[0].name,person[0].sex,&person[0].year,&person[0].zk);
- if(person[0].zk==1)
- {
- printf("检测为已婚,请输入结婚时间,配偶姓名,子女数量:\n");
- /*
- scanf("%s %s %d",&person.settle.havemarried.marriedtime,
- &person.settle.havemarried.spousename,
- &person.settle.havemarried.child);
- */
- scanf("%s %s %d",person[0].settle.havemarried.marriedtime,
- person[0].settle.havemarried.spousename,
- &person[0].settle.havemarried.child);
- }
- else if(person[0].zk==2)
- {
- printf("检测为离婚,请输入离婚时间,以及子女数量:\n");
- /*
- scanf("%s %d",&person.settle.divorce.divorcetime,
- &person.settle.divorce.child);
- */
- scanf("%s %d",person[0].settle.divorce.divorcetime,
- &person[0].settle.divorce.child);
- }
- }
- printf("\n");
- printf("姓名\t性别\t年龄\t婚姻状况\n");
- //for(i=0;i<NUM;i++);
- for(i=0;i<NUM;i++)
- {
- //if(person.zk==1)
- if(person[0].zk==1)
- /*
- printf("%s\t%s\t%d\t结婚日期: %s 配偶姓名:%s 子女数量:%d\n",&person.name,&person.sex,
- &person.year,&person.settle.havemarried.marriedtime,&person.settle.havemarried.spousename,&person.settle.havemarried.child);
- */
- printf("%s\t%s\t%d\t结婚日期: %s 配偶姓名:%s 子女数量:%d\n",person[0].name,person[0].sex,
- person[0].year,person[0].settle.havemarried.marriedtime,person[0].settle.havemarried.spousename,person[0].settle.havemarried.child);
- //else if(person.zk==2)
- else if(person[0].zk==2)
- /*
- printf("%s\t%s\t%d\t离婚日期:%s \t\t子女数量:%d\n",
- &person.name,&person.sex,&person.year,&person.settle.divorce.divorcetime,&person.settle.divorce.child);
- */
- printf("%s\t%s\t%d\t离婚日期:%s \t\t子女数量:%d\n",
- person[0].name,person[0].sex,person[0].year,person[0].settle.divorce.divorcetime,person[0].settle.divorce.child);
- else
- //printf("%s\t%s\t%d\t单身yyds!\n",person.name,person.sex,person.year);
- printf("%s\t%s\t%d\t单身yyds!\n",person[0].name,person[0].sex,person[0].year);
- }
- return 0;
- }
复制代码
|
|