求C语言!用switch编写一个计算分段函数的程序!

2024-11-24 04:48:58
推荐回答(2个)
回答1:

main()
{
int
a,b,c;//a是输入测试值,b是分段值,c是条件标志
printf("input
the
value
and
percentils:\n");
scanf("%d
%d",&a,&b);
//判断a值
if(a>=b)
c=1;
else
c=0;
switch(c)
{
case
1;//a的函数计算
;break;
default://a的函数计算
}
}

回答2:

//100分制
#include

void
main()
{
int
score,t;
printf("输入成绩:");
scanf("%d",&score);
t=score/10;//t的取值0,1,2,3,4,5,6,7,8,9,10
switch(t)
{
case
0:
case
1:
case
2:
case
3:
case
4:
case
5:printf("不及格\n");break;
case
6:printf("及格\n");break;
case
7:
case
8:printf("良好\n");break;
case
9:
case
10:printf("优秀\n");break;
}
}