qq_31586711

2015-09-25 11:03 阅读 2.2k

新手求助，关于switch-case的问题

S(Strength) 信号强度即大小.

Barely readable, occasional words distinguishable
Readable with considerable difficulty
Readable with practically no difficulty

Faint signals, barely perceptible
Very weak signals
Weak signals
Fair signals
Fairly good signals
Good signals
Moderately strong signals
Strong signals
Extremely strong signals

Extremely strong signals, perfectly readable.

33

Weak signals, readable with considerable difficulty.

#include
int main()
{
int rs,r = 0,s = 0;
char*a,*b;
scanf("%d",&rs);
s = rs % 10;
if (s != 0)
{

``````    if (rs >= 11 && rs <= 59 )
{
r = rs / 10;
s = rs % 10;
switch (r)
{
case 1:
break;
case 2:
a = "Barely readable, occasional words distinguishable";
break;
case 3:
a = "Readable with considerable difficulty";
break;
case 4:
a = "Readable with practically no difficulty";
break;
case 5:
break;
}
switch (s)
{
case 1:
b = "faint signals, barely perceptible.";
break;
case 2:
b = "very weak signals.";
break;
case 3:
b = "weak signals.";
break;
case 4:
b = "fair signals.";
break;
case 5:
b = "fairly good signals.";
break;
case 6:
b = "good signals.";
break;
case 7:
b = "moderately strong signals.";
break;
case 8:
b = "strong signals.";
break;
case 9:
b = "extremely strong signals.";
break;
}

printf("%s, %s",a,b);

}

}
return 0;
``````

}

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享

2条回答默认 最新

• qq_31586711 2015-09-25 11:24
`````` #include <stdio.h>
int main()
{
int rs, r = 0, s = 0;
char *a,*b;
scanf("%d", &rs);
s = rs % 10;
if (rs >= 11 && rs <= 59 && s != 0)
{
r = rs / 10;
s = rs % 10;
switch (r)
{
case 1:
break;
case 2:
a = "Barely readable,occasional words distinguishable";
break;
case 3:
a = "Readable with considerable difficulty";
break;
case 4:
a = "Readable with practically no difficulty";
break;
case 5:
a = "Perfectly readable";
break;
}
switch (s)
{
case 1:
b = "faint signals,barely perceptible";
break;
case 2:
b = "very weak signals";
break;
case 3:
b = "weak signals";
break;
case 4:
b = "fair signals";
break;
case 5:
b = "fairly good signals";
break;
case 6:
b = "good signals";
break;
case 7:
b = "moderately strong signals";
break;
case 8:
b = "strong signals";
break;
case 9:
b = "extremely strong signals";
break;
}

printf("%s, %s.", a, b);

}
return 0;

}
``````
点赞 评论 复制链接分享
• 泰 戈 尔 2016-09-21 05:29

楼上的那个代码足够了。s

点赞 评论 复制链接分享