#include<stdio.h>int count[5]const char *str[5] = {"1-59: ","60-69: ","70-79: ","80-89: ","90-100: "}int main(void){int score,i while(1){scanf("%d",&score) if(score==-1)break if(score>=1 &&score <=59)count[0]++ else if(score >= 60 &&score<=69)count[1]++ else if(score>=70 &&score<=79)count[2]++ else if(score>=80 &&score<=89)count[3]++ else if(score>=90 &&score<=100)count[4]++ elseprintf("输入错误") } for(i = 0i <5i++){printf("%s%d\n",str[i],count[i]) }return 0}#include <stdio.h> //使用printf函数要包含的头文件void main(void) //主函数
{
int n
int x1=0,x2=0,x3=0,x4=0,x5=0
printf("请输入学生的成绩1~100:\n")
scanf("%d",&n)
while(n!=-1)
{
if(1<=n&&n<=59)
{
x1+=1
}
else if(60<=n&&n<=69)
{
x2+=1
}
else if(70<=n&&n<=79)
{
x3+=1
}
else if(80<=n&&n<=89)
{
x4+=1
}
else
{
x5=+1
}
scanf("%d",&n)
}
printf("1~59分数段的人数为:%d\n",x1)
printf("60~69分数段的人数为:%d\n",x2)
printf("70~79分数段的人数为:%d\n",x3)
printf("80~89分数段的人数为:%d\n",x4)
printf("90~100分数段的人数为:%d\n",x5)
}
评论列表(0条)