C语言——第六周作业
題目
題目一:高速公路超速處罰
1.實驗代碼
#include <stdio.h> int main() {int speed,maxspeed;double x;scanf("%d %d",&speed,&maxspeed);x=(double)(speed-maxspeed)/(double)maxspeed*100;if(x<10)printf("OK");else if(x>=50)printf("Exceed %.0f%%. License Revoked",x);elseprintf("Exceed %.0f%%. Ticket 200",x);return 0; }2.設計思路
①算法
Begin
輸入speed,maxspeed ? ? ? ? ? ? ? ? ? ? //分別表示實際速度和車道限速
計算x的值 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//x為實際速度超出車道限速的百分比的值
判斷x值的大小,并輸出不同結(jié)果?
end
②流程圖
?
?
3.本題未遇到問題
4.本題PTA提交列表
?
題目二:計算油費
1.實驗代碼
#include <stdio.h> int main() {int a = 0;float b,price,discount,money;char c;scanf("%d %2f %c",&a,&b,&c);if( b == 90){price = 6.95;}if( b == 93){price = 7.44;}if( b == 97){price = 7.93;}if( c == 'm'){discount = 0.05;}if( c == 'e'){discount = 0.03;}money = a * price * (1 - discount);printf("%.2f",money);}?
2.設計思路
①算法
Begin
輸入a,b,c ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//a代表加油量,b代表汽油品種,c代表服務類型
判斷b的值,定義price的值 ? ? ? ? ? ? ? ? ? ? ?//通過判斷不同品種的汽油,定義不同的單價
判斷c的值,定義discount的值 ? ? ? ? ? ? ? ? ? //通過判斷不同類型的服務,定義不同的折扣比例
計算money ? ? ? ? ? ? ? ? ? ? ? ? ?//利用money = a * price * (1 - discount)這一公式計算應付款
輸出money的值
end
②流程圖
?
?
3.本題未遇到問題
4.本題PTA提交列表
?
題目三:比較大小
1.實驗代碼
#include <stdio.h> int main() {int a,b,c,x,y,z;scanf("%d %d %d",&a,&b,&c);if( a > b){x = a;z = b;}else{x = b;z = a;}if( c > x){x = c;}else{if(c < z){z = c;}}y = a + b + c - x -z;printf("%d->%d->%d",z,y,x);}?
2.設計思路
①算法
Begin
輸入a,b,c
判斷a與b的值的大小,將較大的值賦給x,較小的值賦給z。 ? ? ? ? ? ? ? ? ? ? ? ?//定義x為最大值,z為最小值,y為中間值
判斷a、b中較大值與c的值的大小。若c大,將c賦給x。
否則,判斷c是否小于a、b中較小值。若是,將c賦給z。
中間值y為三個數(shù)之和減去最大值與最小值。
輸出z->y->x
end
②流程圖
?
?
3.本題未遇到問題
4.本題PTA提交列表
?
題目四:兩個數(shù)的簡單計算器
1.實驗代碼
#include <stdio.h> int main() {int a,b,answer;char c;scanf("%d %c %d",&a,&c,&b);switch (c){case '+':answer = a + b;printf("%d",answer);break;case '-':answer = a - b;printf("%d",answer);break;case '*':answer = a * b;printf("%d",answer);break;case '/':answer = a / b;printf("%d",answer);break;case '%':answer = a % b;printf("%d",answer);break;default:printf("ERROR");}return 0; }?
2.設計思路
①算法
Begin
輸入 a c b; ? ? ? ? ? ? ? ? ? ? ? ? //a、b為輸入的兩個整數(shù),c為運算符
判斷c為何種符號
若合法,計算并輸出a與b經(jīng)過此種運算符運算后的結(jié)果
若不合法,輸出ERROR
②流程圖
?
?
3.本題起初并未按照作業(yè)要求使用switch語句,經(jīng)過同學提醒修正。
初始if語句代碼:
#include <stdio.h> int main() {int a,b,answer;char c;scanf("%d %c %d",&a,&c,&b);if( c == '+'){answer = a + b;printf("%d",answer);}else if( c == '-'){answer = a - b;printf("%d",answer);}else if( c == '*'){answer = a * b;printf("%d",answer);}else if( c == '/'){answer = a / b;printf("%d",answer);}else if( c == '%'){answer = a % b;printf("%d",answer);}else{printf("ERROR");}}?
4.本題PTA提交列表
?
我的git地址:https://git.coding.net/dx200798/sixth.git
項目截圖
?
個人總結(jié)
一、本周學習內(nèi)容:
1.學習了while語句、do...while語句、for語句這三個循環(huán)語句,并學習了三種循環(huán)的互相嵌套。
2.學習了break語句和continue語句。
3.練習了IF語句和switch語句,提高了對語句應用的熟練度。
二、疑點難點:
對for語句還沒有比較熟練掌握,還需要練習。
三、對目前老師上課形式并沒有什么意見,無法提出意見。
?
互評和學習進度
互評鏈接
鏈接一:http://www.cnblogs.com/fengzx/p/7801506.html
鏈接二:http://www.cnblogs.com/lixiaojing/p/7798963.html
鏈接三:http://www.cnblogs.com/exo123/p/7811906.html
圖表
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/dx2017/p/7794801.html
總結(jié)
以上是生活随笔為你收集整理的C语言——第六周作业的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js中bind、call、apply函数
- 下一篇: 什么是内存(二):虚拟内存