函数接口定义:
double m_tax(double salary,int month);//计算每月累计应纳税额
函数返回每月累计应纳税额;
裁判测试程序样例:
#include<stdio.h>
double m_tax(double salary,int month);
int main()
{
double money,tax,sum=0;
int i;
for(i=1;i<=12;i++)
{
scanf("%lf",&money);
sum+=money;
tax=m_tax(money,i);
printf("the sum of %d months tax is %.2f\n",i,tax);
}
return 0;
}
/* 请在这里填写答案 */
double sum=0;
double m_tax(double salary,int month)
{
double s,tax;
sum+=salary;
if(sum<=month*5000)
tax=0;
else
{
s=sum-month*5000;
if(s<=36000)
tax=s*0.03;
else if(s<=144000)
tax=s*0.1-2520;
else if(s<=300000)
tax=s*0.2-16910;
else if(s<=420000)
tax=s*0.25-31920;
else if(s<=660000)
tax=s*0.30-52920;
else if(s<=960000)
tax=s*0.35-85920;
else
tax=sum*0.45-181920;
}
return tax;
}
double m_tax(double salary,int month)
{
int count_salary = salary - month * 5000;
int tax = 0;
if( count_salary > 0)
{
if(count_salary<36000)
{
return count_salary * 0.03;
}
else if( count_salary>36000 && count_salary < 144000)
{
return 36000 * 0.03 + (count_salary - 36000)*0.1;
}
else if( count_salary > 144000 && count_salary < 300000)
{
return 36000 * 0.03 + (144000 - 36000)*0.1 + count_salary - 144000 * 0.2;
}
else if( count_salary > 300000 && count_salary < 420000)
{
return 36000 * 0.03 + (144000 - 36000)*0.1 + (300000 - 144000) * 0.2 + (count_salary - 300000) * 0.25;
}
else if( count_salary > 420000 && count_salary < 660000)
{
return 36000 * 0.03 + (144000 - 36000)*0.1 + (300000 - 144000) * 0.2 + (420000 - 300000) * 0.25 + (count_salary - 420000) * 0.3;
}
else if( count_salary > 660000 && count_salary < 960000)
{
return 36000 * 0.03 + (144000 - 36000)*0.1 + (300000 - 144000) * 0.2 + (420000 - 300000) * 0.25 + (660000 - 420000) * 0.3 + (count_salary - 660000) * 0.35;
}
else if( count_salary > 960000)
{
return 36000 * 0.03 + (144000 - 36000)*0.1 + (300000 - 144000) * 0.2 + (420000 - 300000) * 0.25 + (660000 - 420000) * 0.3 + (960000 - 660000) * 0.35 + (count_salary - 960000) * 0.45;
}
}
else
{
return 0;
}
}
int main()
{
double money,tax,sum=0;
int i;
for(i=1;i<=12;i++)
{
scanf("%lf",&money);
sum+=money;
tax=m_tax(sum,i);//这里需要传sum
printf("the sum of %d months tax is %.2f\n",i,tax);
}
return 0;
}
#include<stdio.h>
double m_tax(double salary,int month)
{
if(salary<=5000*month)
return 0.0;
else
{
if((salary-5000*month)<36000)
{
return (salary-5000*month)*0.03;
}
else if((salary-5000*month)>=36000&&(salary-5000*month)<144000)
{
return (salary-5000*month)*0.1;
}
else if((salary-5000*month)>=144000&&(salary-5000*month)<300000)
{
return (salary-5000*month)*0.2;
}
else if((salary-5000*month)>=300000&&(salary-5000*month)<420000)
{
return (salary-5000*month)*0.25;
}
else if((salary-5000*month)>=420000&&(salary-5000*month)<660000)
{
return (salary-month*5000)*0.3;
}
else if((salary-5000*month)>=660000&&(salary-5000*month)<960000)
{
return (salary-month*5000)*0.35;
}
else
{
return (salary-month*5000)*0.45;
}
}
}
int main()
{
double money[12],tax[12],sum=0;
for(int i=0; i<12; i++)
{
scanf("%lf",&money[i]);
sum+=money[i];
tax[i]=m_tax(sum,i+1);
}
for(int i=1; i<=12; i++)
{
printf("the sum of %d months tax is %.2f\n",i,tax[i-1]);
}
return 0;
}