本文目录一览:
在C语言编程中,给出一个百分制成绩,要求输出成绩等级
#include stdio.h
int main()
{
int score, m;
scanf("%d", score);
while (score 0 || score 100){
printf("Error! Retry!\n");
scanf("%d", score);
}
m= score / 10;
if (m= 9)
printf("Grade is A!\n");
switch(m){
case 0: printf("Grade is E!\n"); break;
case 1: printf("Grade is E!\n"); break;
case 2: printf("Grade is E!\n"); break;
case 3: printf("Grade is E!\n"); break;
case 4: printf("Grade is E!\n"); break;
case 5: printf("Grade is E!\n"); break;
case 6: printf("Grade is D!\n"); break;
case 7: printf("Grade is C!\n"); break;
case 8: printf("Grade is B!\n"); break;
}
return 0;
}
扩展资料:
其他实现输出成绩等级‘A'、’B‘、'C'、‘D'、'E’。90分以上为A,80~89分为B,70~79分为C,60~69分为D,60分一下为E的方法:
#include stdio.h
int main()
{
int score;
scanf("%d", score);
while (score 0 || score 100){
printf("Error! Retry!\n");
scanf("%d", score);
}
if (score 60)
printf("Grade is E!\n");
else if (score = 60 score 70)
printf("Grade is D!\n");
else if (score = 70 score 80)
printf("Grade is C!\n");
else if (score =80 score 90)
printf("Grade is B!\n");
else
printf("Grade is A!\n");
return 0;
}
C语言:将一个百分制的成绩转化成5个等级
#includestdio.h
int main ()
{
float s=1;
int n;
char ch;
scanf("%f",s);//输入成绩
n=s/10;//除以10转为个位数,如:98/10取整后n=9
switch(n){
case 10:
case 9:ch='A';break;//90+包括100都是A,所以case10不用break
case 8:ch='B';break;
case 7:ch='C';break;
case 6:ch='D';break;
default:ch='E';
}
printf("%c\n",ch);
return 0;
}
C语言 函数 求全班成绩的等级?
代码文本:
#include "stdio.h"
double tol_ave(int a[],int n,int *s){
int i;
for(*s=0,i=0;in;*s+=a[i++]);
return *s/(n+0.0);
}
void level(int a[],int n){
int v,g,m,p,f;
for(v=g=m=p=f=0,n--;n=0;n--){
v += a[n]=90;
g += a[n]=80 a[n]90;
m += a[n]=70 a[n]80;
p += a[n]=60 a[n]70;
f += a[n]60;
}
printf("优秀\t良好\t中等\t及格\t不及格\n");
printf("======================================\n");
printf(" %d\t %d\t %d\t %d\t %d\n",v,g,m,p,f);
}
int main(int argc,char *argv[]){
int sum,a[1000],i,n;
double ave;
printf("输入学生人数:");
if(scanf("%d",n)!=1 || n1 || n1000){
printf("Input error, exit...\n");
return 0;
}
printf("请输入%d个学生的成绩...\n",n);
for(i=0;in;scanf("%d",a+i++));//输入成绩
ave=tol_ave(a,n,sum);
printf("\n总 分: %d\t平均分: %.2f\n",sum,ave);
printf("\n等级分布如下:\n");
level(a,n);
putchar('\n');
return 0;
}