c语言怎么编程个人所得税问题

时间:2025-01-29 02:55:16 网络游戏

示例1:使用结构体数组和for循环计算个人所得税

```c

include

define TAXBASE 3500

typedef struct {

long start;

long end;

double taxrate;

} TAXTABLE;

TAXTABLE TaxTable[] = {

{0, 1500, 0.03},

{1500, 4500, 0.10},

{4500, 9000, 0.20},

{9000, 35000, 0.25},

{35000, 55000, 0.30},

{55000, 80000, 0.35},

{80000, LONG_MAX, 0.45}

};

double CaculateTax(long income) {

int i;

double tax = 0.0;

income -= TAXBASE;

for (i = 0; i < sizeof(TaxTable) / sizeof(TAXTABLE); i++) {

if (income > TaxTable[i].end) {

tax += (TaxTable[i].end - TaxTable[i].start) * TaxTable[i].taxrate;

} else {

tax += (income - TaxTable[i].start) * TaxTable[i].taxrate;

break;

}

income -= TaxTable[i].end;

}

return tax;

}

int main() {

long income;

printf("请输入您的收入金额:");

scanf("%ld", &income);

double tax = CaculateTax(income);

printf("您应缴纳的个人所得税为:%.2f元\n", tax);

return 0;

}

```

示例2:使用if-else语句计算个人所得税

```c

include

double single_tax(double income) {

double tax = 0.0;

if (income <= 3500) {

return 0;

} else if (income <= 1500) {

tax = (income - 3500) * 0.03;

} else if (income <= 4500) {

tax = (1500 - 3500) * 0.10 + (income - 1500) * 0.20;

} else if (income <= 9000) {

tax = (4500 - 1500) * 0.10 + (9000 - 4500) * 0.20;

} else if (income <= 35000) {

tax = (9000 - 4500) * 0.20 + (income - 9000) * 0.25;

} else if (income <= 55000) {

tax = (35000 - 9000) * 0.25 + (income - 35000) * 0.30;

} else if (income <= 80000) {

tax = (55000 - 35000) * 0.30 + (income - 55000) * 0.35;

} else {

tax = (income - 80000) * 0.35 + (100000 - 80000) * 0.45;

}

return tax;

}

int main() {

double income;

printf("请输入您的收入金额:");

scanf("%lf", &income);

double tax = single_tax(income);

printf("您应缴纳的个人所得税为:%.2f元\n", tax);

return 0;

}

```

示例3:使用多个if-else语句计算个人所得税