C Primier Plus(第六版)第9章 编程练习 VS2019测试

本文详细介绍了C Primer Plus第六版第9章的编程练习,包括从第1题到第11题的解题思路和实现,旨在帮助读者巩固C语言的知识并提升编程能力。

第1题

/*编程练习9.1 设计一个函数min(x,y),返回两个double类型值的较小值。在一个简单的驱动程序中测试该函数*/
#include<stdio.h>
float min(float x, float y);

int main(void)
{
   
   
	float m , n;

	printf("Enter a pair of number( q to quit).\n");
	while (scanf_s("%f %f", &m, &n) == 2)
	{
   
   
		printf("The lesser of %.2f and %.2f is %.2f.\n", m, n, min(m, n));
		printf("Enter a pair of number( qo to quit).\n");
	}
	return 0;
}

float min(float x, float y)
{
   
   
	return (x < y)?  x: y;
}

第2题

/*设计一个函数chline(ch,i,j),打印指定的字符j行i列。在一个简单的驱动程序中测试该函数*/
#include<stdio.h>
char chline(char ch, int i, int j);

int main(void)
{
   
   
	char ch;
	int row, column;

	printf("Enter a character and a pair of integers( q to quit).\n");
	while ((ch = getchar()) != 'q')
	{
   
   
		while (scanf_s("%d %d", &row, &column) == 2)
			chline(ch, row, column);
	}
	return 0;
}

char chline(char ch, int i, int j)
{
   
   
	int row, column;
	for (row = 1; row <= i; row++) {
   
   
		for (column = 1; column <= j; column++)
			putchar(ch);
		putchar('\n');
	}
	return 0;
}

第3题

/*编程练习9.3 编写一个函数,接受3个参数:一个字符何两个整数(略),和9.2同,行列对调*/
/*设计一个函数chline(ch,i,j),打印指定的字符j行i列。在一个简单的驱动程序中测试该函数*/
#include<stdio.h>
char chline(char ch, int i, int j);

int main(void)
{
   
   
	char ch;
	int row, column;

	printf("Enter a character and a pair of integers( q to quit).\n");
	while ((ch = getchar()) != 'q')
	{
   
   
		while (scanf_s("%d %d", &row, &column) == 2)
			chline(ch, row, column);
	}
	return 0;
}

char chline(char ch, int i, int j)
{
   
   
	int row, column;
	for (column = 1; column <= j; column++) {
   
   
		for (row = 1; row <= i; row++)
			putchar(ch)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值