1、6.1 “/*下面代码的功能是将百分制成绩转换为 5 分制成绩,具体功能是:如果用户输入的是非法字符或者不在合理区间内的数据(例如输入的是 a,或者 102,或-45 等),则程序输出 Input error!,并允 许用户重新输入,直到输入合法数据为止,并将其转换为 5 分制输出。目前程序存在错误,请将其修改正确。并按照下面给出的运行示例 检查程序。*/#include#include int main()char score100;int flag = 0, i, s;char grade;printf(“Please input score:n“);while (1)flag=0;sca
2、nf(“%s“, score);for (i = 0; i = 0 printf(“Please input score:n“);continue;elsebreak;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;elsegrade = E;printf(“grade: %cn“, grade);return 0;“6.2 “#include#includeint main()int n,a,i,j;double
3、 p=0,q=0;printf(“Input a,n:n“);scanf( “%d,%d“,for(i=1;iint main()int year,month,day;printf(“Input year,month:n“);scanf(“%d,%d“,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: day=30;break;case 7: day=31;break;case 8: day=3
4、1;break;case 9: day=30;break;case 10: day=31;break;case 11: day=30;break;case 12: day=31;break;default:day=-1;printf(“Input error!n“);if(year%4=0if (day!=-1)printf(“%d daysn“,day);return 0;“7.1 “#include unsigned int ComputeAge(unsigned int n)main()int i, j, k, s = 23, n, c, age;scanf(“%d“, printf(“
5、The persons age is %un“,8+2*n);“7.2 “#include int gys(int a,int b)int r;r=a%b;if(r=0) return b;else return gys(b,r);main()printf(“Input a,b:“);int a,b;scanf(“%d,%d“, if (aint median(int a, int b, int c)if(aa)return a;/cabelsereturn cb? c: b;/acb: abcmain()int a,b,c;scanf(“%d%d%d“, printf(“The result
6、 is %dn“,median (a,b,c);“7.4 “#include main()printf(“Input n(nint main()printf(“Input n:“);int n;scanf(“%d“,printf(“Input %d*%d matrix:n“,n,n);int mnn,i,j;for (i=0;iint main()printf(“Input n(nint main()int i,j,k,m,tk,tm;for (i=0;iint main()int a55,i,j,t,row5=0,col5=0,dl1=0,dl2=0,flag=1;for (i=0;i5;i+)for (j=0;j5;j+)scanf(“%d“,for (i=0;i5;i+)for (j=0;j5;j+)rowi+=aij;for (i=0;i5;i+)for (j=0;j5;j+)coli+=aji;for (i=0;i5;i+)dl1+=aii;dl2+=a4-i4-i;for (i=0;i4;i+)if (coli!=coli+1)flag=0;break;if (rowi!=rowi+1)flag=0;break;if (col1!=row1)flag=0;if (dl1!=dl2)flag=0;