C语言程序设计现代方法第二版 第十三章答案

1#include<stdio.h>
#include<string.h>
#define N 20
int main(void)
{
   
	char smallest_word[N+1],largest_word[N+1];
	char ch[N+1];
	
		printf("Enter word:");
		scanf("%s",ch);
		strcpy(smallest_word,ch);
		strcpy(largest_word,ch);
		int x;
		x=strlen(ch);
		if(x==4)
		{
   
			return 0;
		}
		for(;;){
   
			printf("Enter word:");
		scanf("%s",ch);
		if(strcmp(ch,smallest_word)<=0)
			strcpy(smallest_word,ch);
		if(strcmp(ch,largest_word)>=0)
			strcpy(largest_word,ch);
		if(strlen(ch)==4)
			break;
		else continue;
		}
		printf("\nSmallest word:%s\n",smallest_word);
		printf("largest word:%s\n",largest_word);
		return 0;
}



2#include<stdio.h>
#include<string.h>
#define x 50
#define y 60
int read_line(char str[],int n);
int strcmp1(char t[],char k[]);
int main(void)
{
   
	char ch[x][y+3];
	char ch2[x][6],ch3[x][6];
	char d[6];
	char q[y+1];
	int day1,day2;
	int i,j,z=0;
	for(;;){
   
		printf("Enter day and reminder:");
		scanf("%2d/%2d",&day1,&day2);
		if(day1==0)
			break;
		else if(day2<0||day2>31){
   
			printf("error\n");
			continue;}
		sprintf(d,"%2d/%2d",day1,day2);
		read_line(q,y);
		for(i=0;i<z;i++)
			if( strcmp1(d,ch2[i])<0){
   
				break;}
			else {
   if( strcmp1(d,ch2[i])==0)
			{
     if(strcmp(q,ch3[i])<0)
			break;}
			else {
   continue;}
			}

		for(j=z;j>i;j--)
			strcpy(ch[j],ch[j-1]);
		    strcpy(ch2[i],d);
			strcpy(ch[i],d);
		strcat(ch[i],q);
		strcpy(ch3[i],q);
	     z++;
	}
	printf("\nDay Reminder\n");
	for(i=0;i<z;i++)
		printf(" %s\n",ch[i]);
	return 0;
}
int read_line(char str[],int n)
{
   
	int ch1,i=0;
	while((ch1=getchar())!='\n')
		if(i<n)
			str[i++]=ch1;
	if(i>60)printf("No space left\n");
	str[i]='\0';
	return i;
}
  int strcmp1(char t[],char k[]){
   
	  int i=0;
	  for(;i<5;i++)
	  {
   
		  if(t[i]>k[i])
			  return 1;
		  else if(t[i]<k[i])
			  return -1;
		  else continue;
	  }
	  return 0;
  }
3#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#define NUM_SUITS 4
#define NUM_RANKS 13

int main(void)
{
   
	bool in_hand[NUM_SUITS][NUM_RANKS]={
   false};
	int num_cards,rank,suit;
	char rank_code1[][10]={
   "ace","two","three","four","five","six","seven","eight","nine","ten","joker","queen","king"};
	char suit_code1[4][10]={
   "spade","heart","club","diamond"};
	char (*rank_code)[10]=&rank_code1[0];
	char (*suit_code)[10]=&suit_code1[0];
	srand((unsigned)time(NULL));
	printf("Enter number of cards in hand:");
	scanf("%d",&num_cards);
	printf("You hand:");
	while(num_cards>0){
   
		suit=rand()%NUM_SUITS;
		rank=rand()%NUM_RANKS;
		if(!in_hand[suit][rank]){
   
			in_hand[suit][rank]=true;
			num_cards--;
			rank_code=rank_code+rank;
			suit_code=suit_code+suit;
			printf("%s of %s\n",*rank_code,*suit_code);
			rank_code=rank_code-rank;
			suit_code=suit_code-suit;
		}
	}
	printf("\n");
	return 0;
}
4#include <stdio.h>

int main(int argc, char *argv[])
{
   
  int i;

  for (i = 2; i < argc; i++)
    printf("%s ", argv[i]);
  printf("\n");

  return 0;
}
5#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(int argc, char *argv[<
  • 6
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值