日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言——第六周作业

發布時間:2025/4/9 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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值的大小,并輸出不同結果?

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為三個數之和減去最大值與最小值。

輸出z->y->x

end

②流程圖

?

?

3.本題未遇到問題

4.本題PTA提交列表

?

題目四:兩個數的簡單計算器

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為輸入的兩個整數,c為運算符

判斷c為何種符號

若合法,計算并輸出a與b經過此種運算符運算后的結果

若不合法,輸出ERROR

②流程圖

?

?

3.本題起初并未按照作業要求使用switch語句,經過同學提醒修正。

初始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

項目截圖

?

個人總結

一、本周學習內容:

1.學習了while語句、do...while語句、for語句這三個循環語句,并學習了三種循環的互相嵌套。

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

圖表

?

?

轉載于:https://www.cnblogs.com/dx2017/p/7794801.html

總結

以上是生活随笔為你收集整理的C语言——第六周作业的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。