谭浩强【C语言程序设计】第九章习题详解

这篇具有很好参考价值的文章主要介绍了谭浩强【C语言程序设计】第九章习题详解。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

 谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解


1.定义一个结构体变量(包括年、月、日)。计算该日在本年中是第几天,注意闰年问题。

#include <stdio.h>

struct date
{
	int year;
	int month;
	int day;
}d;

int main()
{
	int day[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	printf("请输入年 月 日:\n");
	scanf("%d%d%d", &d.year, &d.month, &d.day);
	int days = 0;
	for (int i = 1; i < d.month; i++)
	{
		days += day[i];
	}
	days += d.day;
	if (d.year % 4 == 0 && d.year % 100 != 0 || d.year % 400 == 0)
	{
		if (d.month > 2)
		{
			days++;
		}
	}
	printf("该日在%d年%d月%d日是第%d天。\n", d.year, d.month, d.day, days);

	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

2.写一个函数days,实现第1题的计算。由主函数将年、月、日传递给 days函数,计算后将日子数传回主函数输出。

#include <stdio.h>

struct date
{
	int year;
	int month;
	int day;
}d;

int days(int year, int month, int day)
{
	int day_tab[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	int day_sum = 0;
	for (int i = 1; i < d.month; i++)
	{
		day_sum += day_tab[i];
	}
	day_sum += d.day;
	if (d.year % 4 == 0 && d.year % 100 != 0 || d.year % 400 == 0)
	{
		if (d.month > 2)
		{
			day_sum++;
		}
	}
	return day_sum;
}

int main()
{
	printf("请输入年 月 日:\n");
	scanf("%d%d%d", &d.year, &d.month, &d.day);
	int day_sum = days(d.year, d.month, d.day);
	printf("该日在%d年%d月%d日是第%d天。\n", d.year, d.month, d.day, day_sum);

	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

3.编写一个函数 print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括 num, name, score[3],用主函数输入这些记录,用 print函数输出这些记录。

#include <stdio.h>
#define N 5

struct student
{
	char num[6];
	char name[8];
	int score[3];
}stu[N];

void print(struct student stu[6])
{
	printf("\n num   name   score1  score2  score3\n");
	for (int i = 0; i < N; i++)
	{
		printf("%4s%6s", stu[i].num, stu[i].name);
		for (int j = 0; j < 3; j++)
		{
			printf("%8d", stu[i].score[j]);
		}
		printf("\n");
	}

}

int main()
{
	for (int i = 0; i < N; i++)
	{
		printf("请输入第%d个学生的的成绩:>\n", i + 1);
		printf("num:");
		scanf("%s", stu[i].num);
		printf("name:");
		scanf("%s", stu[i].name);
		for (int j = 0; j < 3; j++)
		{
			printf("score %d:", j + 1);
			scanf("%d", &stu[i].score[j]);
		}
		printf("\n");
	}

	print(stu);
	
	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

4.在第3题的基础上,编写一个函数 input,用来输入5个学生的数据记录。

#include <stdio.h>
#define N 5

struct student
{
	char num[6];
	char name[8];
	int score[3];
}stu[N];

void print(struct student stu[6])
{
	printf("\n num   name   score1  score2  score3\n");
	for (int i = 0; i < N; i++)
	{
		printf("%4s%6s", stu[i].num, stu[i].name);
		for (int j = 0; j < 3; j++)
		{
			printf("%8d", stu[i].score[j]);
		}
		printf("\n");
	}

}

void input(struct student stu[])
{
	for (int i = 0; i < N; i++)
	{
		printf("请输入第%d个学生的的成绩:>\n", i + 1);
		printf("num:");
		scanf("%s", stu[i].num);
		printf("name:");
		scanf("%s", stu[i].name);
		for (int j = 0; j < 3; j++)
		{
			printf("score %d:", j + 1);
			scanf("%d", &stu[i].score[j]);
		}
		printf("\n");
	}
}

int main()
{
	input(stu);
	print(stu);
	
	return 0;
}

5.有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)。

#include <stdio.h>
#define N 3

struct student
{
	char num[6];
	char name[8];
	float score[3];
	float avg;
}stu[N];

int main()
{
	for (int i = 0; i < N; i++)
	{
		printf("请输入第%d个学生的的数据:>\n", i + 1);
		printf("num:");
		scanf("%s", stu[i].num);
		printf("name:");
		scanf("%s", stu[i].name);
		for (int j = 0; j < 3; j++)
		{
			printf("score %d:", j + 1);
			scanf("%f", &stu[i].score[j]);
		}
	}
	//计算
	float average = 0, max = 0;
	int maxi = 0;
	float sum = 0;
	for (int i = 0; i < N; i++)
	{
		sum = 0;
		for (int j = 0; j < 3; j++)
		{
			sum += stu[i].score[j];//计算第i个学生总分
		}
		stu[i].avg = sum / 3.0;//计算第i个学生平均分
		average += stu[i].avg;
		if (sum > max)//找分数最高者
		{
			max = sum;
			maxi = i;//将此学生的下标保存在maxi
		}
	}
	average /= N;//计算总平均分数
	printf("\n num  name  score1 score2 score3  average\n");
	for (int i = 0; i < N; i++)
	{
		printf("%3.2s%6.2s", stu[i].num, stu[i].name);
		for (int j = 0; j < 3; j++)
		{
			printf("%8.2f", stu[i].score[j]);
		}
		printf("%8.2f\n", stu[i].avg);

	}
	printf("\naverage=%5.2f\n", average);
	printf("最高成绩是:student %s, %s\n", stu[maxi].num, stu[maxi].name);
	printf("他的成绩是:%6.2f,%6.2f,%6.2f,average:%5.2f\n", stu[maxi].score[0], stu[maxi].score[1], stu[maxi].score[2], stu[maxi].avg);
	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

6.13个人围成一圈,从第1个人开始顺序报号1,2,3。凡报到3者退出圈子。找出最后留在圈子中的人原来的序号。要求用链表实现。

#include <stdio.h>
#define NUM 13

//定义节点
typedef struct people
{
	int num;
	struct people* next;
}people;

int main()
{
	//定义包含13个人的数据
	people arr[NUM];

	//建立环状链表
	people* head = arr;
	for (int i = 0; i < NUM; i++)
	{
		head->num = i + 1;
		head->next = &arr[i + 1];
		head = head->next;
	}
	//构成环状链表
	arr[NUM - 1].next = arr;

	//开始报数
	int count = NUM;
	//从1开始报数
	int i = 1;
	head = arr;
	while (count > 1)
	{
		//1.判断是否已经退出
		if (head->next == 0)
		{
			//跳过此人
			head = head->next;
			continue;
		}
		if (i == 3)
		{
			//当前此人需要退出
			printf("第%d个人退出\n", head->num);
			head->num = 0;
			count--;
		}
		//继续报号
		i++;
		head = head->next;

		//判断报号是否大于3
		if (i > 3)
		{
			i = 1;
		}
	}
	//找出编号不为0的人
	while (head->num == 0)
	{
		//找下一个人
		head = head->next;
		if (head->num != 0)
		{
			printf("没有退出的人为:%d\n", head->num);
		}
	}
	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

7. 在第9章例9.9和例9.10的基础上,写一个函数del,用来删除动态链表中指定的结点。

#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
	int num;
	struct node* next;
}node;

//创建链表:创建一个含有n个节点的链表,返回头节点的指针
node* creat(int n)
{
	//创建一个头节点
	node* head = (node*)malloc(sizeof(node));
	head->num = 0;
	head->next = NULL;
	node* p = head;

	//创建数据为1~n的节点
	for (int i = 1; i <= n; i++)
	{
		node* newNode = (node*)malloc(sizeof(node));
		newNode->num = i;
		newNode->next = NULL;

		p->next = newNode;
		p = p->next;
	}
	return head;
}

//打印链表数据
void printNode(node* head)
{
	//第一个数据为head->next
	node* p = head->next;
	while (p != NULL)
	{
		printf("node %d\n", p->num);
		p = p->next;
	}
}

void del(node* head, int val)
{
	node* prev = head;
	node* p = head;
	//遍历链表,找到需要删除的节点
	while (p != NULL)
	{
		if (p->num == val)
		{
			prev->next = p->next;
			free(p);
			break;
		}
		else
		{
			prev = p;
			p = p->next;
		}
	}
}

int main()
{
	node* head = creat(10);
	int n;
	printf("当前链表的所有节点:\n");
	printNode(head);
	printf("请输入需要删除的节点编号:\n");
	scanf("%d", &n);
	del(head, n);
	//删除之后链表的节点
	printf("删除之后链表的节点:\n");
	printNode(head);

	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

8. 写一个函数 insert,用来向一个动态链表插入结点。

#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
	int num;
	struct node* next;
}node;

void insert(node* p, int n)
{
	//创建节点
	node* newNode = (node*)malloc(sizeof(node));
	newNode->num = n;

	//链接
	newNode->next = p->next;
	p->next = newNode;
}

node* creat(int n)
{
	//创建含有n个有效数据的节点
	//创建一个带头的链表
	node* head = (node*)malloc(sizeof(node));
	head->num = 0;
	head->next = NULL;
	node* p = head;

	//创建有效数据的节点
	for (int i = 1; i <= n; i++)
	{
		node* newNode = (node*)malloc(sizeof(node));
		newNode->num = i;
		newNode->next = NULL;

		p->next = newNode;
		p = p->next;
	}
	return head;
}

void printNode(node* head)
{
	//从第一个有效数据开始打印
	node* p = head->next;
	while (p != NULL)
	{
		printf("node %d\n", p->num);
		p = p->next;
	}
}

int main()
{
	int n;
	node* head = creat(10);
	printf("未插入数据之前的原始列表:\n");
	printNode(head);
	printf("请输入需要插入的数据:\n");
	scanf("%d", &n);
	insert(head, n);
	printf("插入数据之后的链表:\n");
	printNode(head);
	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

9.综合本章例9.9(建立链表的函数 creat)、例9.10(输出链表的函数 print)和本章习题第7题(删除链表中结点的函数dei)、第8题(插入结点的函数 insert),再编写一个主函数,先后调用这些函数。用以上5个函数组成一个程序,实现链表的建立、输出、删除和插入,在主函数中指定需要删除和插入的结点的数据。

#include <stdio.h>
#include <stdlib.h>

#define CNT 3

//定义节点
typedef struct node
{
	int num;
	struct node* next;
}node;

//创建链表:从控制台输入数据
node* creat()
{
	//首先创建一个头节点,不存放有效数据
	node* head = (node*)malloc(sizeof(node));
	head->next = NULL;
	head->num = 0;
	node* p = head;
	printf("创建一个含有%d个数据的单链表\n", CNT);
	printf("请输入%d个数据:", CNT);
	for (int i = 0; i < CNT; i++)
	{
		int n;
		scanf("%d", &n);
		node* newNode = (node*)malloc(sizeof(node));
		newNode->num = n;
		newNode->next = NULL;

		//链接
		p->next = newNode;
		p = p->next;
	}
	return head;
}

//打印链表
void printNode(node* head)
{
	node* p = head->next;
	while (p != NULL)
	{
		printf("node: %d\n", p->num);
		p = p->next;
	}
}

//删除节点
void del(node* head, int val)
{
	//遍历链表,找到待删除的位置
	node* p = head->next;
	node* prev = head;
	while (p != NULL)
	{
		if (p->num == val)
		{
			prev->next = p->next;
			free(p);
			break;
		}
		else
		{
			prev = p;
			p = p->next;
		}
	}
}

//插入节点
void insert(node* p, int val)
{
	//给p节点的后面插入新的数据
	node* newNode = (node*)malloc(sizeof(node));
	newNode->num = val;
	newNode->next = NULL;

	newNode->next = p->next;
	p->next = newNode;
}

int main()
{
	printf("创建链表:\n");
	node* head = creat();
	printf("创建链表结束:\n");
	printf("初始链表:\n");
	printNode(head);
	printf("请输入需要插入的数据:\n");
	int n;
	scanf("%d", &n);
	insert(head, n);
	printf("插入数据: %d之后,链表的所有数据:\n",n);
	printNode(head);
	printf("请输入需要删除的数据:\n");
	scanf("%d", &n);
	del(head, n);
	printf("删除数据:%d之后,链表的所有数据:\n", n);
	printNode(head);

	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

10.已有 a,b两个链表,每个链表中的结点包括学号、成绩。要求把两个链表合并,按学号升序排列。

#include <stdio.h>
#include <stdlib.h>

#define NUM 5

typedef struct node
{
	int num;
	float score;
	struct node* next;
}node;

node* creat()
{
	printf("请输入%d个数据:学号 成绩\n", NUM);
	node* head = NULL;
	//链表的表尾
	node* tail = NULL;
	for (int i = 0; i < NUM; i++)
	{
		int num;
		float score;
		scanf("%d%f", &num, &score);
		//创建节点
		node* newNode = (node*)malloc(sizeof(node));
		newNode->num = num;
		newNode->score = score;
		newNode->next = NULL;
		//插入到已有链表
		//判断当前链表是否为空
		if (head == NULL)
		{
			head = tail = newNode;
		}
		else
		{
			//把新的节点插入到尾节点后面
			tail->next = newNode;
			tail = newNode;
		}
	}
	return head;
}

//合并,排序两个链表
node* mergeList(node* a, node* b)
{
	//合并
	node* head = a;
	while (head->next != NULL)
	{
		head = head->next;
	}
	head->next = b;

	head = a;
	//prev:未排序的第一个节点
	node* prev = a;
	//排序,选择排序
	while (prev->next != NULL)
	{
		//每次从未排序的节点中选择一个学号最小的
		//放在第一个未排序节点的位置
		node* cur = prev->next;
		while (cur)
		{
			if (prev->num > cur->num)
			{
				//把学号最小的数据往前移动
				int num = prev->num;
				float score = prev->score;

				prev->num = cur->num;
				prev->score = cur->score;

				cur->num = num;
				cur->score = score;
			}
			cur = cur->next;
		}
		prev = prev->next;
	}
	return head;
}

void printNode(node* a)
{
	while (a != NULL)
	{
		printf("学号:%d 成绩:%f\n", a->num, a->score);
		a = a->next;
	}
}

int main()
{
	node* a = creat();
	node* b = creat();
	printf("链表a的数据:\n");
	printNode(a);
	printf("链表b的数据:\n");
	printNode(b);
	printf("合并a和b\n");
	a = mergeList(a, b);
	printNode(a);

	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

11.有两个链表 a和b,设结点中包含学号、姓名。从a链表中删去与b链表中有相同学号的那些结点。

#include <stdio.h>
#include <stdlib.h>

#define LEN 20

typedef struct node
{
	int num;
	char name[LEN];
	struct node* next;
}node;

//返回新链表的表头
node* del(node* a, node* b)
{
	node* head = a;
	//遍历b中的每一个节点
	while (b)
	{
		//从a的表头开始遍历
		node* prev = a;
		node* cur = prev->next;
		//用头节点和b当前指向的节点进行比较
		if (prev->num == b->num)
		{
			prev->next = NULL;
			//更新表头
			head = cur;
		}
		//用非头节点和b当前指向的节点进行比较
		else
		{
			while (cur)
			{
				if (cur->num == b->num)
				{
					//删除当前节点
					prev->next = cur->next;
					cur->next = NULL;
					break;
				}
				else
				{
					//继续向后遍历
					prev = cur;
					cur = cur->next;
				}
			}
		}
		//处理b的下一个节点
		b = b->next;
	}
	return head;
}

void printNode(node* head)
{
	while (head)
	{
		printf("%d-->%s\n", head->num, head->name);
		head = head->next;
	}
}

int main()
{
	//建立链表
	node a[5] = { {3, "zhang"}, {1, "wang"},{15, "li"},{10, "zhou"},{8, "ren"} };
	node b[3] = { {8, "ren"}, {3, "zhang"}, {10, "zhou"}};
	for (int i = 0; i < 5; i++)
	{
		a[i].next = &a[i + 1];
	}
	a[4].next = NULL;
	
	for (int i = 0; i < 3; i++)
	{
		b[i].next = &b[i + 1];
	}
	b[2].next = NULL;
	printf("链表a:\n");
	printNode(a);
	printf("链表b:\n");
	printNode(b);

	node* head = del(a, b);
	printf("删除之后的链表:\n");
	printNode(head);

	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解

12.建立一个链表,每个结点包括:学号、姓名、性别、年龄。输入一个年龄,如果链表中的结点所包含的年龄等于此年龄,则将此结点删去。

#include <stdio.h>
#define LEN 20

typedef struct node
{
	int num;
	char name[LEN];
	char gender[LEN];
	int age;
	struct node* next;
}node;

node* del(node* a)
{
	int age;
	printf("请输入需要删除的年龄:\n");
	scanf("%d", &age);
	//遍历删除
	node* prev = NULL;
	node* cur = a;
	node* head = a;
	while (cur)
	{
		if (cur->age == age)
		{
			//当前节点需要删除
			//头节点
			if (prev == NULL)
			{
				//更新头节点
				head = cur->next;
			}
			//非头节点
			else
			{
				prev->next = cur->next;
			}
			//查看下一个节点
			cur = cur->next;
		}
		else
		{
			//当前节点不需要删除
			prev = cur;
			cur = cur->next;
		}
	}
	return head;
} 

void printNode(node* head)
{
	while (head)
	{
		printf("%d %s %s %d\n", head->num, head->name, head->gender, head->age);
		head = head->next;
	}
}

int main()
{
	node arr[] = { {1, "wang", "male", 20}, {2, "li", "female", 30}, 
		{3, "zhang", "male", 20}, {4, "li", "female", 18}, {5, "cheng", "male", 20} };
	//建立链表
	for (int i = 0; i < 5; i++)
	{
		arr[i].next = &arr[i + 1];
	}
	arr[4].next = NULL;

	printf("链表的所有数据:\n");
	printNode(arr);
	node* head = del(arr);
	printf("删除之后链表的剩余数据:\n");
	printNode(head);

	return 0;
}

谭浩强【C语言程序设计】第九章习题详解,谭浩强【C程序设计】习题详解,c语言,开发语言,谭浩强C语言程序设计,第九章习题详解文章来源地址https://www.toymoban.com/news/detail-825362.html

到了这里,关于谭浩强【C语言程序设计】第九章习题详解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Python语言程序设计 习题1

    一、选择题 1.python语言属于(C) A.机器语言    B.汇编语言   C.高级语言   D.科学计算语言 2.下列选项中,不属于python特点的是(B) A.面向对象   B.运行效率高   C.可读性好   D.开源 3.python程序文件的扩展名是(D) A.  .python   B.  .pyt    C.   .pt    D.   .py 4.以下叙述

    2024年02月08日
    浏览(19)
  • 编译原理1.6习题 程序设计语言基础

    图源:文心一言 编译原理习题整理~🥝🥝 作为初学者的我,这些习题主要用于自我巩固。由于是自学,答案难免有误,非常欢迎各位小伙伴指正与讨论!👏💡 第1版:自己的解题,与AI老师的判卷~🧩🧩 编辑: 梅头脑🌸  审核: 文心一言 题源: 龙书《编译原理》 Alfre

    2024年01月19日
    浏览(23)
  • C++语言程序设计第五版 - 郑莉(第六章课后习题)

    6-20 实现一个名为 SimpleCircle 的简单圆类。其数据成员 int* itsRadius 为一个指向其半径值的指针,存放其半径值。设计对数据成员的各种操作,给出这个类的完整实现并测试这个类。 6-21 编写一个函数,统计一条英文句子中字母的个数,在主程序中实现输入输出。 6-22 编写函数

    2023年04月25日
    浏览(23)
  • 《python语言程序设计基础》(第二版)第五章课后习题参考答案

    第五章 函数和代码的复用 5.1 改造练习题3.5,输出更大的田字格 5.2 实现isOdd函数 5.3 实现isNum函数 5.4 实现multi函数 5.5 实现isPrime函数 5.6 输出10种生日日期格式 代码一: 代码二: 5.7 汉诺塔 注:上述代码仅供参考,若有问题可在评论区留言!

    2024年02月01日
    浏览(24)
  • 《python语言程序设计基础》(第二版)第六章课后习题参考答案

    第六章 组合数据类型 6.1 随机密码生成 6.2 重复元素判定 6.3 重复元素判定续 6.4 文本字符分析 6.5 生日悖论分析 6.6 《红楼梦》人物统计 注:上述代码仅供参考,若有问题可在评论区留言! 《红楼梦》及人物名单TXT (百度云链接失效可在评论区留言) 链接:https://pan.baidu.c

    2024年02月05日
    浏览(23)
  • 《python语言程序设计基础》(第二版)第二章课后习题参考答案

    第二章 Python程序实例解析 2.1 温度转换 2.2 汇率兑换 优化: 优化的主要改动: 将货币符号和金额分离出来,使代码更加清晰易读。 将条件判断改为根据货币符号进行判断,避免重复判断。 2.3 绘制彩色蟒蛇 2.4 等边三角形的绘制 代码一: 代码二: 2.5 叠加等边三角形的绘制

    2024年03月19日
    浏览(26)
  • 浙大版《C语言程序设计实验与习题指导(第3版)》题目集

    本题要求编写程序,输出整数152的个位数字、十位数字和百位数字的值。 输入格式:本题无输入。 输出格式:按照以下格式输出:

    2023年04月17日
    浏览(21)
  • 浙大版《C语言程序设计》第四版(何钦铭颜晖) 第7章 数组 课后习题答案

    你也可以上程序咖(https://meta.chengxuka.com),打开大学幕题板块,不但有答案,讲解,还可以在线答题。 一、选择题 1.假定 int 类型变量占用两个字节,则以下定义的数组 a 在内存中所占字节数是( )。 A. 20 B.10 C.6 D.3 答:A 解析:题目中,根据 int a[10] ,表示定义了数组的长度

    2023年04月18日
    浏览(25)
  • C++ Primer第五版_第九章习题答案(51~52)

    练习9.51 设计一个类,它有三个unsigned成员,分别表示年、月和日。为其编写构造函数,接受一个表示日期的string参数。你的构造函数应该能处理不同的数据格式,如January 1,1900、1/1/1990、Jan 1 1900 等。

    2023年04月11日
    浏览(17)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包