永发信息网

C语言题目——帮忙解释下

答案:3  悬赏:30  手机版
解决时间 2021-05-07 23:08
  • 提问者网友:我是女神我骄傲
  • 2021-05-07 04:39

#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
帮忙详细解释下

最佳答案
  • 五星知识达人网友:底特律间谍
  • 2021-05-07 05:07

#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函数输出
}


全部回答
  • 1楼网友:独行浪子会拥风
  • 2021-05-07 07:18

#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函数输出

  • 2楼网友:一袍清酒付
  • 2021-05-07 06:39
建议你单步跟踪调试一下 其实就是简单的计算 用比画一画就知道了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯