|
Post by huangno1 on Dec 26, 2016 20:55:56 GMT -8
輸入一個分數,輸出其等級,評定規則如下:
100~90: Grade A
89~80: Grade B
79~70: Grade C
69~60: Grade D
59~0: Grade F
其餘分數輸出 Invalid score。
範例一
輸入: 100
輸出: Grade A
範例二
輸入: 60
輸出: Grade F
範例三
輸入: 101
輸出 Invalid score
***以下為程式碼***
#include <stdio.h>
int main()
{
int score = 0 ;
scanf ( " %d" , &score ) ;
if (score > 100 || score < 0) printf ( "Invalid score" ) ;
else if (score <= 100 && score >= 90) printf ( "Grade A" ) ;
else if (score < 90 && score >= 80) printf ( "Grade B" ) ;
else if (score < 80 && score >= 70) printf ( "Grade C" ) ;
else if (score < 70 && score >= 60) printf( "Grade D" ) ;
else if (score < 60 && score>= 0) printf ( "Grade F" ) ;
return 0 ;
}
|
|