主题:求助if...if
[code=c]
请填写代码
[/code]
#include <stdio.h>
void main(){
int x;
double y,z,p;
printf("input the number of the people\n");
scanf("%d",&x);
scanf("%lf",&y);
z = (y-3.5*x)/(3.5*x);
/* if(z<=0)
p = y*3.7;
else if(z<=0.2)
p = 3.5*x*3.7+3.7*2*(y-3.5*x);
else if(z<=0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*(y-3.5*x*(1+0.2));
else
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*0.2*3.5*x+3.7*4*(y-3.5*x*(1+0.4));
*/
if(z<=0)
p = y*3.7;
if(0<z<=0.2)
p = 3.5*x*3.7+3.7*2*(y-3.5*x);
if(0.2<z<=0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*(y-3.5*x*(1+0.2));
if(z>0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*0.2*3.5*x+3.7*4*(y-3.5*x*(1+0.4));
/*if(z<=0)
p = y*3.7;
if(0<z&&z<=0.2)
p = 3.5*x*3.7+3.7*2*(y-3.5*x);
if(0.2<z&&z<=0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*(y-3.5*x*(1+0.2));
if(z>0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*0.2*3.5*x+3.7*4*(y-3.5*x*(1+0.4));*/
printf("is %lf\n",p);
}
其中if(0<z&&z<=0.2)与if(0<z<=0.2)有什么不同?
请填写代码
[/code]
#include <stdio.h>
void main(){
int x;
double y,z,p;
printf("input the number of the people\n");
scanf("%d",&x);
scanf("%lf",&y);
z = (y-3.5*x)/(3.5*x);
/* if(z<=0)
p = y*3.7;
else if(z<=0.2)
p = 3.5*x*3.7+3.7*2*(y-3.5*x);
else if(z<=0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*(y-3.5*x*(1+0.2));
else
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*0.2*3.5*x+3.7*4*(y-3.5*x*(1+0.4));
*/
if(z<=0)
p = y*3.7;
if(0<z<=0.2)
p = 3.5*x*3.7+3.7*2*(y-3.5*x);
if(0.2<z<=0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*(y-3.5*x*(1+0.2));
if(z>0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*0.2*3.5*x+3.7*4*(y-3.5*x*(1+0.4));
/*if(z<=0)
p = y*3.7;
if(0<z&&z<=0.2)
p = 3.5*x*3.7+3.7*2*(y-3.5*x);
if(0.2<z&&z<=0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*(y-3.5*x*(1+0.2));
if(z>0.4)
p =3.5*x*3.7+3.7*2*3.5*x*0.2+3.7*3*0.2*3.5*x+3.7*4*(y-3.5*x*(1+0.4));*/
printf("is %lf\n",p);
}
其中if(0<z&&z<=0.2)与if(0<z<=0.2)有什么不同?