#include <stdio.h>
struct card{
char *face;
char *suit;
};
void filldeck(struct card *wdeck, char *wface[],char *wsuit[])
{ int i;
for (i = 0; i < 4; i++){
wdeck[i].face = wface[i%2];
wdeck[i].suit = wsuit[i/2];
}
}
void deal(struct card *wdeck)
{ int i;
for (i = 0; i < 4; i++)
printf("(%2s of %-6s)\n", wdeck[i].face, wdeck[i].suit);
}
void main()
{ struct card deck[4];
char *face[]={"K","Q"};
char *suit[]={"Heart","Club"};
filldeck(deck,face,suit);
deal(deck);
}
(21) 程序运行时,第1行输出 (21) 。
A、(K of Heart) B、(Q of Heart)
C、(K of Club) D、(Q of Club)
(22) 程序运行时,第2行输出 (22) 。
A、(K of Heart) B、(Q of Heart)
C、(K of Club) D、(Q of Club)
(23) 程序运行时,第3行输出 (23) 。
A、(K of Heart) B、(Q of Heart)
C、(K of Club) D、(Q of Club)
(24) 程序运行时,第3行输出 (24) 。
A、(K of Heart) B、(Q of Heart)
C、(K of Club) D、(Q of Club)
ABCD
帮忙详细解释下
#include <stdio.h>
struct card
{
char *face;
char *suit;
};
void filldeck(struct card *wdeck, char *wface[],char *wsuit[])//用指针来改变值
{
int i;
for (i = 0; i < 4; i++)
{
wdeck[i].face = wface[i%2];//第一次循环...依次 等于0 1 0 1 第一个循环face[0]
wdeck[i].suit = wsuit[i/2];//第一次循环...依次等于0 0 1 1 第一个循环suit[0]
}
}
void deal(struct card *wdeck)
{
int i;
for (i = 0; i < 4; i++)
printf("(%2s of %-6s)\n", wdeck[i].face, wdeck[i].suit);
}
void main()
{
struct card deck[4];
char *face[]={"K","Q"};
char *suit[]={"Heart","Club"};
filldeck(deck,face,suit);//调用 传数组首地址
deal(deck);//调用deal函数输出
}
#include <stdio.h>
struct card
{
char *face;
char *suit;
};
void filldeck(struct card *wdeck, char *wface[],char *wsuit[])//用指针来改变值
{
int i;
for (i = 0; i < 4; i++)
{
wdeck[i].face = wface[i%2];//第一次循环wdeck[0].face = wface[0],2:wdeck[1].face = wface[1]
3:wdeck[2].face = wface[0] 4:2:wdeck[3].face = wface[1]
wdeck[i].suit = wsuit[i/2];//第一次循环wdeck[0].suit = wsuit[0] 2:wdeck[1].suit = wsuit[0]
3:wdeck[2].suit = wsuit[1] 4:wdeck[3].suit = wsuit[1]
}
}
void deal(struct card *wdeck)
{
int i;
for (i = 0; i < 4; i++)
printf("(%2s of %-6s)\n", wdeck[i].face, wdeck[i].suit);//1输出K of Heart 2:Q of Heart
3:K of Club 4:Q of Club
}
void main()
{
struct card deck[4];
char *face[]={"K","Q"};
char *suit[]={"Heart","Club"};
filldeck(deck,face,suit);//调用 传数组首地址
deal(deck);//调用deal函数输出
}
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息