C语言学习之分别用if和switch编程,输入0-100分成绩,输出相应的成绩档次。
生活随笔
收集整理的這篇文章主要介紹了
C语言学习之分别用if和switch编程,输入0-100分成绩,输出相应的成绩档次。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
3.分別用if和switch編程,輸入0-100分成績,輸出相應的成績檔次。
設: 90分以上為’A’; 80-89 分為’B’; 70~79 分為’C’; 60-69 分為’D’;60分以下為E’。
if語句
#include <stdio.h> void main(){int grade;printf("請輸入成績:\n");scanf("%d",&grade);printf("grade=%d",grade);if(grade>=90){printf("成績為:A");}else if(grade>=80){printf("成績為:B");}else if(grade>=70){printf("成績為:C");}else if(grade>=60){printf("成績為:D");}else{printf("成績為:E");}} }switch語句
#include <stdio.h> void main(){int grade;printf("請輸入成績:\n");scanf("%d",&grade);printf("grade=%d",grade);switch(grade/10%10){case 9:printf("成績為:A");break;case 8:printf("成績為:B");break;case 7:printf("成績為:C");break;case 6:printf("成績為:D");break;default :printf("成績為:E");break;} }不懂請留言,謝謝!
總結
以上是生活随笔為你收集整理的C语言学习之分别用if和switch编程,输入0-100分成绩,输出相应的成绩档次。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言学习之编程输入x,输出对应的y.
- 下一篇: C语言学习之分别用while、for 编