課程
/后端開發
/C
/C語言入門
這個結果對嗎?
2017-12-20
源自:C語言入門 5-14
正在回答
#include <stdio.h>//start_time 上車時間 ,total_km 里程數double TotalAmt(double start_time, double total_km){??? double? unit_price=2.3;??? //每公里單價計費2.3元??? double flag_fall_price = 13;??? //起步價13元(包含3公里)??? double begin_time=23;//每公里單價計費加收20%。開始時間??? double end_time=5;//每公里單價計費加收20%。結束時間??? double additional=1;// 每次乘車加收1元錢的燃油附加稅??? double start_km = 3;??? //起步包含3公里??? double total_amt;//總費用??? if( start_time >= begin_time || start_time < end_time){??????? unit_price *= 1.2;??? }??? if( total_km <= start_km)??? {??????? total_amt = flag_fall_price + additional;??? }??? else??? {??????? total_amt = flag_fall_price + additional + (total_km - start_km) * unit_price; ??? }??? return total_amt;}int main(){??? double amt = 0;??? amt+=(TotalAmt(9,12)+TotalAmt(18,12));??? printf("小明每天打車的總費用為%f元", amt);??? return 0;}
#include?<stdio.h> /** *??@real_miles?double?實際里程數 *??@now_time?double?上車時間 */ double?getTotalMoney(double?real_miles,?double?now_time) { ??? ????int?start,?gasPlus,?miles,?start_miles,?begin_time,?end_time,?now; ????double?per,?total; ???? ????miles?=?(int)real_miles;????//對乘客友好的floor型實際里程數 ????now?=?(int)now_time;????//上車時間 ???? ????//定義常量 ????begin_time?=?23;??//夜間增收起始時間 ????end_time?=?5;????//早間增收截止時間 ????start?=?13;????//起步費 ????gasPlus?=?1;????//燃油費 ????per?=?2.3;????//單價 ????start_miles?=?3;????//起步公里3公里 ???? ????if(?now?>?begin_time?||?now?<=?end_time){ ????????per?*=?1.2; ????} ???? ????if(?miles?<=?start_miles){ ????????total?=?start?+?gasPlus; ????}else?{ ????????total?=?start?+?gasPlus?+?(miles?-?start_miles)?*?per;? ????} ????return?total; ???? } int?main() { ????double?totalMoney?=?0; ????totalMoney?+=?getTotalMoney(12,?9); ????totalMoney?+=?getTotalMoney(12,?18); ????printf("小明每天打車的總費用為%f元",?totalMoney); ????return?0; }
#include <stdio.h>
double getTotalMoney(double real_miles, double now_time)
{
? ?
? ? int start, gasPlus, miles, start_miles, begin_time, end_time, now;
? ? double per, total;
? ??
? ? miles = (int)real_miles;
? ? now = (int)now_time;
? ? begin_time = 23;
? ? end_time = 5;
? ? start = 13;
? ? gasPlus = 1;
? ? per = 2.3;
? ? start_miles = 3;
? ? if( now > begin_time || now <= end_time){
? ? ? ? per *= 1.2;
? ? }
? ? if( miles <= start_miles){
? ? ? ? total = start + gasPlus;
? ? }else {
? ? ? ? total = start + gasPlus + (miles - start_miles) * per;?
? ? return total;
}
int main()
? ? double totalMoney = 0;
? ? totalMoney += getTotalMoney(12, 9);
? ? totalMoney += getTotalMoney(12, 18);
? ? printf("小明每天打車的總費用為%f元", totalMoney);
? ? return 0;
舉報
C語言入門視頻教程,帶你進入編程世界的必修課-C語言
1 回答循環結構之三種循環結構的比較
1 回答為啥算完之后是153天??
1 回答為什么運算結果不是相加的結果?
1 回答循環結構之多重結構
2 回答分支結構之switch語句的case
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-12-22
#include <stdio.h>
//start_time 上車時間 ,total_km 里程數
double TotalAmt(double start_time, double total_km)
{
??? double? unit_price=2.3;??? //每公里單價計費2.3元
??? double flag_fall_price = 13;??? //起步價13元(包含3公里)
??? double begin_time=23;//每公里單價計費加收20%。開始時間
??? double end_time=5;//每公里單價計費加收20%。結束時間
??? double additional=1;// 每次乘車加收1元錢的燃油附加稅
??? double start_km = 3;??? //起步包含3公里
??? double total_amt;//總費用
??? if( start_time >= begin_time || start_time < end_time){
??????? unit_price *= 1.2;
??? }
??? if( total_km <= start_km)
??? {
??????? total_amt = flag_fall_price + additional;
??? }
??? else
??? {
??????? total_amt = flag_fall_price + additional + (total_km - start_km) * unit_price;
??? }
??? return total_amt;
}
int main()
{
??? double amt = 0;
??? amt+=(TotalAmt(9,12)+TotalAmt(18,12));
??? printf("小明每天打車的總費用為%f元", amt);
??? return 0;
}
2017-12-20
2017-12-20
#include <stdio.h>
double getTotalMoney(double real_miles, double now_time)
{
? ?
? ? int start, gasPlus, miles, start_miles, begin_time, end_time, now;
? ? double per, total;
? ??
? ? miles = (int)real_miles;
? ? now = (int)now_time;
? ??
? ? begin_time = 23;
? ? end_time = 5;
? ? start = 13;
? ? gasPlus = 1;
? ? per = 2.3;
? ? start_miles = 3;
? ??
? ? if( now > begin_time || now <= end_time){
? ? ? ? per *= 1.2;
? ? }
? ??
? ? if( miles <= start_miles){
? ? ? ? total = start + gasPlus;
? ? }else {
? ? ? ? total = start + gasPlus + (miles - start_miles) * per;?
? ? }
? ? return total;
? ??
}
int main()
{
? ? double totalMoney = 0;
? ? totalMoney += getTotalMoney(12, 9);
? ? totalMoney += getTotalMoney(12, 18);
? ? printf("小明每天打車的總費用為%f元", totalMoney);
? ? return 0;
}