C Primer Plus 第九章 函数 编程练习答案(自作)

// Page 237, 9.11编程练习

9.11.1. 设计一个函数min(x, y), 返回两个double类型值的较小值。

// 9.11.1

#include <stdio.h>
double min(double x, double y);
int main()
{
	printf("Please enter two real numbers that you want:\n");
	double x, y;
	scanf("%lf %lf", &x, &y);
	printf("min number = %lf\n", min(x, y));
	
	return 0;
}
double min(double x, double y)
{
	double ret;
	if(x > y)
		ret = y;
	else
		ret = x;
	return ret;
}

9.11.2 设计一个函数 chline(ch, i, j),打印指定的字符 j 行 i 列。

// 9.11.2

#include <stdio.h>
void chline(char ch, int a, int b);
int main()
{
	printf("Please enter the character that you want:\n");
	char ch;
	scanf("%c", &ch);
	printf("Then enter the numbers:\n");
	int i, j;
	scanf("%d %d", &j, &i);
	chline(ch, i, j);
	
	return 0;
	
}
void chline(char ch, int a, int b)
{
	char star[b][a];
	int i, j;
	for(i = 0; i < b; i++){
		for(j = 0; j < a; j++){
			star[i][j] = ch;
			printf("%c", star[i][j]);
		}
		putchar('\n');
	}
	return;
}

9.11.3 编写一个函数,接受3个参数:一个字符和两个整数。字符参数是待打印的字符,第一个整数指定一行中打印字符的次数,第二个整数指定打印指定字符的行数。(和上题一样,换个问法)

// 9.11.3

#include <stdio.h>
void func(char, int, int);
int main()
{
	char c;
	int i, j;
	printf("Please enter the character tha
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值