Try   HackMD

11-1 分數等第

CHAWTeam


目錄:DICE C語言程式破解


題目

試一試其他的方法,來解題:

寫一個程式讓使用者輸入分數,印出分數與等級。

分數與等級的換算如下:
100-90 A
89-80 B
79-70 C
69-60 D
59-0 F

因為此題輸出有多種狀況,故需將程式碼複製3次,都判斷正確才給分,每個輸出都要換行。

輸入範例1:
85

輸出範例1:
Your score is 85 and degree is B!

輸入範例2:
63

輸出範例2:
Your score is 63 and degree is D!

C範例程式:
f(x>=90)
    printf("Your score is %d and degree is A!\n",x);
else if(x>=80)
    printf("Your score is %d and degree is B!\n",x);
else if
    (x>=70)printf("Your score is %d and degree is C!\n",x);
else if
    (x>=60)printf("Your score is %d and degree is D!\n",x);
else
    printf("Your score is %d and degree is F!\n",x);

C++範例程式:
cin>>x;
if (x>=90)
    cout<<"Your score is "<<x<<" and degree is A!"<<endl;
else if (x>=80)
    cout<<"Your score is "<<x<<" and degree is B!"<<endl;
else if (x>=70)
    cout<<"Your score is "<<x<<" and degree is C!"<<endl;
else if (x>=60)
    cout<<"Your score is "<<x<<" and degree is D!"<<endl;
else
    cout<<"Your score is "<<x<<" and degree is F!"<<endl;

程式碼

#include <stdio.h> int main() { int x; scanf("%d", &x); if (x >= 90 && x <= 100) printf("Your score is %d and degree is A!\n", x); else if (x >= 80 && x < 90) printf("Your score is %d and degree is B!\n", x); else if (x >= 70 && x < 79) printf("Your score is %d and degree is C!\n", x); else if (x >= 60 && x < 69) printf("Your score is %d and degree is D!\n", x); else printf("Your score is %d and degree is F!\n", x); scanf("%d", &x); if (x >= 90 && x <= 100) printf("Your score is %d and degree is A!\n", x); else if (x >= 80 && x < 90) printf("Your score is %d and degree is B!\n", x); else if (x >= 70 && x < 79) printf("Your score is %d and degree is C!\n", x); else if (x >= 60 && x < 69) printf("Your score is %d and degree is D!\n", x); else printf("Your score is %d and degree is F!\n", x); scanf("%d", &x); if (x >= 90 && x <= 100) printf("Your score is %d and degree is A!\n", x); else if (x >= 80 && x < 90) printf("Your score is %d and degree is B!\n", x); else if (x >= 70 && x < 79) printf("Your score is %d and degree is C!\n", x); else if (x >= 60 && x < 69) printf("Your score is %d and degree is D!\n", x); else printf("Your score is %d and degree is F!\n", x); return 0; }

執行

85
Your score is 85 and degree is B!
63
Your score is 63 and degree is D!
72
Your score is 72 and degree is C!

查看我們在HackMD上的所有筆記
目錄:DICE C語言程式破解


👉【幫我們一個忙!】👈

👋如果您喜歡這篇文章,請在下方按5個Like!
❤您的支持是我們最大的動力!

您只要登入帳號(Facebook、Google),在下方按5個Like,我們就會收到來自LikeCoin基金會的贊助。
您只需要支持我們,完全不會花到錢!