sing_tax.c

来自「c和指针 学习c语言必须阅读的书籍之一 提高对C语言的掌握理解能力」· C语言 代码 · 共 36 行

C
36
字号
/*
** Compute the 1995 U.S. federal income tax for a single taxpayer.
*/

#include <float.h>

static	double	income_limits[]
	= { 0,	 23350,	 56550,	  117950,  256500,	DBL_MAX };
static	float	base_tax[]
	= { 0,	 3502.5, 12798.5, 31832.5, 81710.5 };
static	float	percentage[]
	= { .15, .28,	 .31,	  .36,	   .396 };

double
single_tax( double income )
{
	int	category;

	/*
	** Find the correct income category.  The DBL_MAX added to
	** the end of this list guarantees that the loop will not
	** go too far.
	*/
	for( category = 1;
	    income >= income_limits[ category ];
	    category += 1 )
		;
	category -= 1;

	/*
	** Compute the tax.
	*/
	return base_tax[ category ] + percentage[ category ] *
	    ( income - income_limits[ category ] );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?