哈工大 C语言程序设计精髓 MOOC慕课 6-12周编程题答案

2025-11-20

6.1 \下面代码的功能是将百分制成绩转换为5分制成绩,具体功能是:如果用户输入的是非法字符或者不在合理区间内的数据(例如输入的是a,或者102,或-45等),则程序输出 Input error!,并允许用户重新输入,直到输入合法数据为止,并将其转换为5分制输出。目前程序存在错误,请将其修改正确。并按照下面给出的运行示例检查程序。 */

#include #include int main() {

char score[100];

int flag = 0, i, s; char grade;

printf(\ while (1) {

flag=0; scanf(\

for (i = 0; i < strlen(score); i++) {

if (score[i] >= '0' && score[i] <= '9') {

continue; } else {

flag = 1; break; } }

s = atoi(score);

if (s < 0 || s > 100 || flag == 1) { printf(\printf(\ continue; } else{

break; } }

s = atoi(score);

if (s >= 90) {

grade = 'A'; }

else if (s >= 80) {

grade = 'B'; }

else if (s >= 70) {

grade = 'C'; }

else if (s >= 60) {

grade = 'D'; } else {

grade = 'E'; }

printf(\

return 0; }\

6.2 \#include int main() {

int n,a,i,j; double p=0,q=0; printf(\scanf( \ for(i=1;i<=n;i++) {

for(j=0,p=0;j

p=p+a*pow(10,j); } q=p+q; }

printf(\ return 0; }\6.3 \

n块砖( 27

程序的运行结果示例1: Input n(27

men=0,women=4,children=32

程序的运行结果示例2: Input n(27

men=3,women=3,children=30

程序的运行结果示例3: Input n(27

men=2,women=14,children=20 men=7,women=7,children=22 men=12,women=0,children=24

输入提示: \


哈工大 C语言程序设计精髓 MOOC慕课 6-12周编程题答案.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:渠道(施组)

相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219