---------------------------------------------
if语句
---------------------------------------------
#include
void main()
{
long i;
double b,b1=0,b2=0,b4=0,b6=0,b10=0,other=0;
printf("请输入员工利润:");
scanf("%ld",&i);
b1=100000*0.1; /*利润为10W时所得的奖金*/
b2=(200000-100000)*0.075+b1; /*利润为20W时所得的奖金*/
b4=(400000-200000)*0.05+b2; /*利润为40W时所得的奖金*/
b6=(600000-400000)*0.03+b4; /*利润为60W时所得的奖金*/
b10=(1000000-600000)*0.015+b6; /*利润为100W时所得的奖金*/
other=(i-1000000)*0.01+b10;
if(i<=100000)
{
b=i*0.1;
}
else if(i<=200000 && i>100000)
{
b=(i-100000)*0.075+b1;
}
else if(i<=400000 && i>200000)
{
b=(i-200000)*0.05+b2;
}
else if(i<=600000 && i>400000)
{
b=(i-400000)*0.03+b4;
}
else if(i<=1000000 && i>600000)
{
b=(i-600000)*0.015+b6;
}
else if(i>1000000)
{
b=other;
}
printf("该员工所得奖金为:%.2f\n\n",b);
}
---------------------------------------------
switch语句
---------------------------------------------
#include
void main()
{
long i;
double b,b1=0,b2=0,b4=0,b6=0,b10=0,other=0;
printf("请输入员工利润:");
scanf("%ld",&i);
b1=100000*0.1; /*利润为10W时所得的奖金*/
b2=(200000-100000)*0.075+b1; /*利润为20W时所得的奖金*/
b4=(400000-200000)*0.05+b2; /*利润为40W时所得的奖金*/
b6=(600000-400000)*0.03+b4; /*利润为60W时所得的奖金*/
b10=(1000000-600000)*0.015+b6; /*利润为100W时所得的奖金*/
other=(i-1000000)*0.01+b10;
switch((i-1)/100000)
{
case 0:b=i*0.1;break;
case 1:b=(i-100000)*0.075+b1; break;
case 2:
case 3:b=(i-200000)*0.05+b2; break;
case 4:
case 5:b=(i-400000)*0.03+b4; break;
case 6:
case 7:
case 8:
case 9:b=(i-600000)*0.015+b6;break;
default:b=other; break;
}
printf("该员工所得奖金为:%.2f\n\n",b);
}
n的值要求输入
switch(n\100000)
case 0:这是不满100000的情况.
case 1:这是在100000-199999的情况,再把n-100000后的值剩以7.5%
case 2:这里记得是200000和高于200000并存的情况,加个if判断!
case 3:....
...........
下面就是这样子.自己写吧.
记的在最后那个默认选项里.把过600000的情况全包了.
main()
{
long int i;
int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;
scanf("%ld",&i);
bonus1=100000*0.1;bonus2=bonus1+100000*0.75;
bonus4=bonus2+200000*0.5;
bonus6=bonus4+200000*0.3;
bonus10=bonus6+400000*0.15;
if(i<=100000)
bonus=i*0.1;
else if(i<=200000)
bonus=bonus1+(i-100000)*0.075;
else if(i<=400000)
bonus=bonus2+(i-200000)*0.05;
else if(i<=600000)
bonus=bonus4+(i-400000)*0.03;
else if(i<=1000000)
bonus=bonus6+(i-600000)*0.015;
else
bonus=bonus10+(i-1000000)*0.01;
printf("bonus=%d",bonus);
}
x为工资
1:
if (i<=1000000) x=x*(1+0.1);
else if (i>100000 && i<=200000) x=((100000)*(1+0.1)+(x-100000)*(1+0.075));
else if(i>2000000 && i<=400000) x=(200000*(1+0.075)+(x-200000)*(1+0.05));
else if(i>4000000 && i<=600000) x=(400000*(1+0.05)+(x-400000)*(1+0.003));
else if(i>6000000 && i<=1000000) x=(600000*(1+0.003)+(x-400000)*(1+0.0015));
else if(i>1000000) x=(1000000*(1+0.0015)+(x-1000000)*(1+0.001));
2:
switch(x)
{
case x<=100000 :
x=x*(1+0.1);
break;
case x>100000 && x<=200000:
x=((100000)*(1+0.1)+(x-100000)*(1+0.075));
break;
case x>200000 && x<=400000:
x=(200000*(1+0.075)+(x-200000)*(1+0.05));
break;
case x>400000 && x<=600000:
x=(400000*(1+0.05)+(x-400000)*(1+0.003));
break;
case x>600000 && x<=1000000:
x=(600000*(1+0.003)+(x-400000)*(1+0.0015));
break;
case x>1000000 :
x=(1000000*(1+0.0015)+(x-1000000)*(1+0.001));
#include
main()
{
long int I;
int b1,b2,b4,b6,b10,b;
scanf("%ld",&I);
b1=100000*0.1;
b2=b1+100000*0.075;
b4=b2+200000*0.05;
b6=b4+200000*0.03;
b10=b6+400000*0.015;
if(I<=100000)
b=b10+(I-100000)*0.1;
else if(I<=200000)
b=b1+(I-100000)*0.075;
else if(I<=400000)
b=b2+(I-200000)*0.05;
else if(I<=600000)
b=b4+(I-400000)*0.03;
else if(I<=1000000)
b=b6+(I-600000)*0.015;
else
b=b10+(I-1000000)*0.01;
printf("应发奖金总数是:%d",b);
}
#include
main()
{
long int I;
int b1,b2,b4,b6,b10,b,s;
scanf("%ld",&I);
b1=100000*0.1;
b2=b1+100000*0.075;
b4=b2+200000*0.05;
b6=b4+200000*0.03;
b10=b6+400000*0.015;
s=I/100000;
switch(s) {
case 0:b=I*0.1;break;
case 1:
b=b1+(I-100000)*0.075; break;
case 2:
case 3:
b=b2+(I-200000)*0.05; break;
case 4:
case 5:
b=b4+(I-400000)*0.03; break;
case 6:
case 7:
case 8:
case 9:
b=b6+(I-600000)*0.015; break;
default:
b=b10+(I-1000000)*0.01; break;}
printf("应发奖金总数是:%d",b);
printf("b1=%d,b2=%d,b4=%d,b6=%d,b10=%d",b1,b2,b4,b6,b10);
}