- 59
- 0
- 约3.17万字
- 约 67页
- 2020-11-07 发布于江苏
- 举报
6.1 下面代码功效是将百分制成绩转换为5分制成绩,具体功效是:假如用户输入是非法字符或不在合理区间内数据(比如输入是a,或102,或-45等),则程序输出?Input error!,并许可用户重新输入,直到输入正当数据为止,并将其转换为5分制输出。现在程序存在错误,请将其修更正确。并根据下面给出运行示例检验程序。
#includestdio.h
#include string.h
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;
}
6.2 编程计算a+aa+aaa+…+aa…a(n个a)值(4分)
题目内容:
编程计算 a+aa+aaa+…+aa…a(n个a)值,n和a值由键盘输入。比如,当n=4,a=2,表示计算2+22+222+2222值。
#includestdio.h
#includemath.h
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;ji;j++)
{
p=p+a*pow(10,j);
}
q=p+q;
}
printf(sum=%.0f\n,q);
return 0;
}
6.3搬砖问题(4分)
题目内容:
n块砖(?27n=77?),36人搬,男搬4,女搬3,两个小孩抬一块砖,要求一次搬完,问男人、女人和小孩各需多少人?请用穷举法编程求解,n值要求从键盘输入。输出结果根据男人数量升序给出(见下面示例3)。
#include stdio.h
main()
{
int a, b, c;
long n, i, t, s = 0;
printf(Input n(27n=77):\n);
scanf(%d, n);
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);
}
}
6.4 编程输出某年某月有多少天(考虑到闰年)。(5分)
题目内容:
从键盘输入一个年份和月份,输出该月有多少天(考虑闰年),用switch语句编程。
#include stdio.h
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;
case 3: day=31;break;
case 4: day=30;break;
case 5: day=31;break;
case 6: d
您可能关注的文档
最近下载
- 特定技能2号农业练习题11.docx
- 2026年在带头固本培元、增强党性等五个带头方面对照检查存在的问题、整改措施材料6份文.docx VIP
- 冰川雪山攀登技巧心得分享心得总结.docx VIP
- 小森印刷机s40操作说明.pdf VIP
- 8篇2026年带头固本培元、增强党性(五个带头)方面存在的问题精选.docx VIP
- 翼状胬肉病人护理精品PPT课件.pptx
- 2026年河北省职业病诊断医师资格(尘肺病类)高分突破必练试题库(含答案).docx
- 2024中医临床实践指南穴位埋线减肥.docx VIP
- 人教PEP版五年级下册英语全册教案(单元整体教学设计).docx VIP
- 2025年贵州省公务员考试题及答案解析.docx
原创力文档

文档评论(0)