int main()
{
int morning=9;
int afternoon=18;
int distance=12;
double Price=0;
if(TaxiPrice(morning,distance)!=0)
{
Price=TaxiPrice(morning,distance);
}
if(Price!=0)
{
Price+=TaxiPrice(afternoon,distance);
}
{
int morning=9;
int afternoon=18;
int distance=12;
double Price=0;
if(TaxiPrice(morning,distance)!=0)
{
Price=TaxiPrice(morning,distance);
}
if(Price!=0)
{
Price+=TaxiPrice(afternoon,distance);
}
if(distance<=3){
totalPrice=startPrice;
}else{
totalPrice=startPrice+perPrice*(distance-3);
}
totalPrice+=1;
/*totalPrice+=totalPrice;*/
return totalPrice;
}
totalPrice=startPrice;
}else{
totalPrice=startPrice+perPrice*(distance-3);
}
totalPrice+=1;
/*totalPrice+=totalPrice;*/
return totalPrice;
}
#include <stdio.h>
double TaxiPrice(int hours,int distance)
{
double totalPrice=0.0;
double perPrice=2.3;
double startPrice=13.0;
if(hours<0||hours>24){
printf("输入时间有误");
}else if(hours<5||hours>24){
perPrice*=1.2;
}
double TaxiPrice(int hours,int distance)
{
double totalPrice=0.0;
double perPrice=2.3;
double startPrice=13.0;
if(hours<0||hours>24){
printf("输入时间有误");
}else if(hours<5||hours>24){
perPrice*=1.2;
}
#include <stdio.h>
int main()
{
double num = 2.5; //定义浮点型变量num并赋值为2.5
printf("num的整数部分是%d\n", (int)num);
return 0;
}
1、强制转换是临时性转换的,强制转换类型说明符是否放对位置
2.可以在输出当中强制转换。
int main()
{
double num = 2.5; //定义浮点型变量num并赋值为2.5
printf("num的整数部分是%d\n", (int)num);
return 0;
}
1、强制转换是临时性转换的,强制转换类型说明符是否放对位置
2.可以在输出当中强制转换。
2015-03-13
可以用if(i%2==0),但是只能在for里面用。
for(i=1;i<=100;i++)
{
if(i%2==0)
{
sum=sum-i;
}
else
{
sum=sum+i;
}
}
printf("sum=%d\n",sum);
for(i=1;i<=100;i++)
{
if(i%2==0)
{
sum=sum-i;
}
else
{
sum=sum+i;
}
}
printf("sum=%d\n",sum);
2015-03-13
它的执行过程如下:
第一步:执行表达式1,对循环变量做初始化;
第二步:判断表达式2,若其值为真(非0),则执行for循环体中执行代码块,然后向下执行;若其值为假(0),则结束循环;
第三步:执行表达式3;
第四步:执行for循环中执行代码块后执行第二步;
第五步:循环结束,程序继续向下执行。
第一步:执行表达式1,对循环变量做初始化;
第二步:判断表达式2,若其值为真(非0),则执行for循环体中执行代码块,然后向下执行;若其值为假(0),则结束循环;
第三步:执行表达式3;
第四步:执行for循环中执行代码块后执行第二步;
第五步:循环结束,程序继续向下执行。
2015-03-13