c语言题 要求按照百分制考试成绩输出对应的等级(分别用if和switch,写两种)

85~100为A等,70~84为B等,60~69为C等,60分以下为D等,所输入的成绩为整数。
!!!要求:1、可以实现多个数据的输入,输入-1时程序结束
2、分别用if语句和switch语句实现程序功能

#include <stdio.h>
void judge1(int score);
void judge2(int score);
void main()
{
     int score=0;
     
     scanf("%d",&score);
     
     while(score!=-1)
     {
                     judge1(score);
                     judge2(score);
                     scanf("%d",&score);
     }
     getch();
}
void judge1(int score)
{
     if(score>=85)
                  printf("judge1 --> A\n");
     else if(score>70)
          printf("judge1 --> B\n");
     else if(score>=60)
          printf("judge1 --> C\n");
     else
         printf("judge1 --> D\n");
}
void judge2(int score)
{
     int flag = score/10;
     
     switch(flag)
     {
                 case 10:
                 case 9:printf("judge2 --> A\n");break;
                 case 8:
                      if(score>=85)
                      {
                                   printf("judge2 --> A\n");break;
                      }
                 case 7:printf("judge2 --> B\n");break;
                 case 6:printf("judge2 --> C\n");break;
                 default:
                        printf("judge2 --> D\n"); break;
     }
}

根据你的要求写的,你看看有什么疑问,

温馨提示:内容为网友见解,仅供参考
第1个回答  2013-11-01
使用IF语句实现:
#include<stdio.h>
void main()
{
int x;
scanf("%d",&x);
for(;x!=-1;)
{
if(x>=85&&x<=100)
printf("A等\n");
else
if(x>=70&&x<=84)
printf("B等\n");
else
if(x>=60&&x<=69)
printf("C等\n");
elseif(x>=0&&x<=59)
printf("D等\n");
else
printf("输入有误\n");
scanf("%d",&x);
}
}

使用SWITCH语句实现:
#include<stdio.h>
void main()
{
int x;
scanf("%d",&x);
for(;x!=-1;)
{
switch(x)
{
case x>=85&&x<=100:printf("A等\n");break;
case x>=70&&x<=84: printf("B等\n");break;
case x>=605&&x<=69:printf("C等\n");break;
case x>=0&&x<=59: printf("D等\n");break;
defalut : printf("输入有误\n"); break;
}
scanf("%d",&x);
}
}追问

非常感谢!

第2个回答  2013-11-01
#intclude <stdio.h>
char grade(int score) {
if(score>=85) return A;
else if(score>=70) return B;
else if(score>=60) return C;
else return D;
}
//_______________________________
char level(int score) {
switch((score+5)/15) {
case 7:case 6:return A;
case 5:return B;
case 4: {
switch(score/10) {
case 6:return C;
case 5:return D;
}
}
default:return D;
}
}
//_____________________________
main() {
int flag=1,score;
while(flag!=-1) {
printf("please input the score: ");
scanf("%d",&score);
printf("grade: %c\n",grade(score));
printf("input -1 to exit!");
scanf("%d",&flag);
}
}追问

非常感谢~

c语言题 要求按照百分制考试成绩输出对应的等级(分别用if和switch,写两...
include <stdio.h>void judge1(int score);void judge2(int score);void main(){ int score=0; scanf("%d",&score); while(score!=-1) { judge1(score); judge2(score); scanf("%d",&score); } getch();}void judge1(int score){ if(score>=85) ...

编写C语言程序 用switch结构或if语句 输入成绩 输出等级
include \\x0d\\x0aint main() {\\x0d\\x0a int s, d;\\x0d\\x0a printf("输入成绩(百分制): ");\\x0d\\x0a scanf("%d", &s);\\x0d\\x0a d = s \/ 10;\\x0d\\x0a switch (d) {\\x0d\\x0a case 10:\\x0d\\x0a printf("满分。\\n");\\x0d\\x...

编写C语言程序 用switch结构或if语句 输入成绩 输出等级
include \\x0d\\x0aint main() {\\x0d\\x0a int s, d;\\x0d\\x0a printf("输入成绩(百分制): ");\\x0d\\x0a scanf("%d", &s);\\x0d\\x0a d = s \/ 10;\\x0d\\x0a switch (d) {\\x0d\\x0a case 10:\\x0d\\x0a printf("满分。\\n");\\x0d\\x...

c语言题目:给出一百分制成绩,要求输出成绩等级ABCDE
case 7: printf("Grade is C!\\n"); break;case 8: printf("Grade is B!\\n"); break;} return 0;}

c语言题目求助。编程序,输入一个百分制的成绩t后,按下式输出它的等级...
c='B'; break; case 7: c='C'; break; case 6: c='D'; break; case 5: c='E'; break; default:break;

C语言,输入百分制成绩,输出对应等级
a是int 类型前面应该写float s;int a;scanf("%f",&s);a=int s;\/\/使实数类型 float a; printf("请输入成绩:\\n")switch((int)(a\/10+0.05))case nclude<stdio.h>int main() char score;printf("Please input your score(0~100):\\n");scanf("%c",&score);printf("Your grade:"...

输入一个百分制分数,输出对应的五级计分等级的 C语言程序
void main(){ float score;int n;printf("请输入一个学生的分数\\n");scanf("%f",&score);n=(int)score;switch(n\/10){case 0:case 1:case 2:case 3:case 4:case 5:printf("E 等级\\n");break;case 6:printf("D 等级\\n");break;case 7:printf("C 等级\\n");break;case 8:...

C++利用if和switch编写输出成绩等级的程序
include<iostream>using namespace std;void main(){int s;cout<<"请输入考试成绩"<<endl;cin>>s;switch(s\/10){case 10:case 9:cout<<"成绩为等级A"<<endl;break;case 8:cout<<"成绩为等级B"<<endl;break;case 7:cout<<"成绩为等级C"<<endl;break;case 6:cout<<"成绩为等级D"<<...

用C#输入一个百分制成绩,输出对应的等级。要求用switch语句实现...
if (x > 60)return true;else return false;} } public static class MyExtensions { public static string sort(this string temp){ return temp.convert2int().sort().convert2chararray().CharToString();} public static string CharToString(this char[] temp){ string s = "";for (int...

C语言,输入百分制成绩,输出等级制成绩,(100-90是A级,89-80是B级,79-6...
switch最好,一楼简洁但有小问题 include<stdio.h> void main(){ int a;printf("请输入分数!\\n");scanf("%d",&a);switch (a\/10){ case 10:printf("A\\n");break;case 9:printf("A\\n");break;case 8:printf("B\\n");break;case 7:case 6:printf("C\\n");break;default:printf(...

相似回答