C语言程序设计现代方法第二版,第九章课后编程习题

第一题

#include <stdio.h>
#include<string>

void selection_sort(int n, int a[]) 
{

	int i, j, max = a[0];

	for (i = 0; i < n; i++) 
	{
		if (max <= a[i]) 
		{
			max = a[i];
			j = i;
		}
	}
	a[j] = a[n - 1];
	a[n - 1] = max;
	n--;
	if (n == 0) 
		return;
	else
		selection_sort(n, a);
}
int main(void)
{
	int n;
	printf("How many numbers do you want to resevse? ");
	scanf("%d", &n);
	int a[99];
	printf("Enter the number you want: ");
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	selection_sort(n, a);
	printf("In sorted order: ");
	for (int i = 0; i < n; i++) 
		printf("%d ", a[i]);
	system("pause");
	return 0;
}

第二题

#include <stdio.h>
#include<string>
float js(float income)
{
	float out;
		if (income < 750)
			out = 750 * 0.01;
		else if (income < 2250)
			out = (income - 750)*0.02 + 7.50;
		else if (income < 3750)
			out = (income - 2250)*0.03 + 37.50;
		else if (income < 5250)
			out = (income - 3750)*0.04 + 52.50;
		else if (income < 7000)
			out = (income - 7000)*0.05 + 142.50;
		else
			out = (income - 750)*0.06 + 230.0;
		return out;
}
int main(void)
{
	float income;
	printf("Enter your income:");
	scanf_s("%f", &inc
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值