C语言逻辑推理与判断的题

2025-04-06 01:31:20
推荐回答(2个)
回答1:

#include "stdio.h"
void main()
{
int x,y,z;
for(x=1;x<=3;x++)
for(y=1;y<=3;y++)
for(z=1;z<=3;z++)
if(x!=1&&x!=3&&z!=3&&x!=y&&y!=z&&z!=x)
{
printf("X will marry to %c\n",'A'-1+x);
printf("Y will marry to %c\n",'A'-1+y);
printf("Z will marry to %c\n",'A'-1+z);
}
}

回答2:

#include
char xinlang[3]={'A','B','C'};
void main()
{
int x,y,z;
for(x=1;x<4;x++)
for(y=1;y<4;y++)
{
if(x==y) continue;
z=6-x-y;
if(x!=1&&x!=3&&z!=3)
{
printf("X will marry to %c\n",xinlang[x-1]);
printf("Y will marry to %c\n",xinlang[y-1]);
printf("Z will marry to %c\n",xinlang[z-1]);
}
}
}