哈工大c语言程序设计精髓mooc慕课6-12周编程题答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
"/*下面代码的功能是将百分制成绩转换为5分制成绩,具体功能是:如果用户输入的是非法字符或者不在合理区间内的数据(例如输入的是a,或者102,或-45等),则程序输出 Input error!,并允许用户重新输入,直到输入合法数据为止,并将其转换为5分制输出。目前程序存在错误,请将其修改正确。并按照下面给出的运行示例检查程序。
*/
#include<>
#include <>
int main()
{
char score[100];
int flag = 0, i, s;
char grade;
printf(""Please input score:\n"");
while (1)
{
flag=0;
scanf(""%s"", score);
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(""Input error!\n"");
printf(""Please input score:\n""); 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(""grade: %c\n"", grade); return 0;
}"
"#include<>
#include<>
int main()
{
int n,a,i,j;
double p=0,q=0;
printf(""Input a,n:\n"");
scanf( ""%d,%d"",&a,&n);
for(i=1;i<=n;i++)
{
for(j=0,p=0;j
{
p=p+a*pow(10,j);
}
q=p+q;
}
printf(""sum=%.0f\n"",q);
return 0;
}"
"/*
n块砖( 27 程序的运行结果示例1: Input n(27 28↙ men=0,women=4,children=32程序的运行结果示例2:Input n(27 36↙ men=3,women=3,children=30程序的运行结果示例3:Input n(27 60↙ men=2,women=14,children=20 men=7,women=7,children=22 men=12,women=0,children=24 输入提示: ""Input n(27 输入格式: ""%d"" 输出格式:""men=%d,women=%d,children=%d\n"" */ #include """" main() { printf(""Input n(27 long n, i, t, s = 0; scanf(""%d"", &n); int a, b, c; for (a = 0; 4 * a <= n; a++) for (b = 0; 4 * a + 3 * b <= n; b++) for (c = 0; 4 * a + 3 * b + c / 2 <= n; c += 2) if (4 * a + 3 * b + c / 2 == n && c%2 == 0 && a+b+c==36) { printf(""men=%d,women=%d,children=%d\n"", a, b, c); } }" "#include<> int main() {int year,month,day; printf(""Input year,month:\n""); scanf(""%d,%d"",&year,&month); switch(month) { case 1: day=31;break; case 2: day=28;break;