C語言——第六周作業

來源:互聯網
上載者:User

標籤:blog   定義   erro   這一   需要   百分比   若是   gif   com   

題目

題目一:高速公路超速處罰

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);    else        printf("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語句還沒有比較熟練掌握,還需要練習。

三、對目前老師上課形式並沒有什麼意見,無法提出意見。

 

互評和學習進度

互評連結

連結一:

連結二:

連結三:

圖表

 

 

C語言——第六周作業

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.