第二次作业
1 int main() 2 { 3 int grade; 4 printf("请输入成绩"); 5 scanf("%d",&grade); 6 if(grade<0&&grade>100) 7 { 8 printf("输入错误"); 9 } 10 if(grade>=90) 11 {printf("A"); 12 } 13 else if(grade>=80&&grade<=89) 14 {printf("B"); 15 } 16 else if(grade>70&&grade<=79) 17 {printf("C"); 18 } 19 else if(grade>=60&&grade<=69) 20 {printf("D"); 21 } 22 else if(grade<60&&grade>=0) 23 {printf("E"); 24 } 25 return 0; 26 }
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,c,d,e; 5 printf("输入一个五位数"); 6 scanf("%d",&e); 7 a=e/10000; 8 b=e%10000/1000; 9 c=e%100/10; 10 d=e%10; 11 if(a==d&&b==c) 12 { 13 printf("这是一个回文数\n"); 14 } 15 else 16 { 17 printf("这不是回文数\n"); 18 } 19 return 0; 20 }
1 #include<stdio.h> 2 int main() 3 { 4 int grade; 5 printf("ÇëÊäÈë³É¼¨"); 6 scanf("%d",&grade); 7 switch(grade/10) 8 { 9 case 9:printf("A\n");break; 10 case 8:printf("B\n");break; 11 case 7:printf("C\n");break; 12 case 6:printf("D\n");break; 13 case 5: 14 case 4: 15 case 3: 16 case 2: 17 case 1: 18 case 0:printf("E\n");break; 19 default:printf("error"); 20 } 21 return 0; 22 }
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,c,d,e,f,g; 5 printf("ÊäÈëÊý¾Ý"); 6 scanf("%d",&a) ; 7 if(a>=100000||a<0) 8 { 9 printf("error\n"); 10 } 11 else 12 { 13 if(a>=10000&&a<99999) 14 { 15 b=a/10000; 16 c=a/1000%10; 17 d=a/100%10; 18 e=a/10%10; 19 f=a%10; 20 g=f*10000+e*1000+d*100+c*10+b; 21 printf("¸ÃÊýÊÇÎåλÊý£¬ÄæÐòΪ%d\n",g) ; 22 } 23 else if(a>=1000&&a<9999) 24 { 25 b=a/1000; 26 c=a/100%10; 27 d=a/10%10; 28 e=a/10; 29 f=e*1000+d*100+c*10+b; 30 printf("¸ÃÊýÊÇËÄλÊý£¬ÄæÐòΪ%d\n",f); 31 } 32 else if(a>=100&&a<999) 33 { 34 b=a/100; 35 c=a/10%10; 36 d=a%10; 37 e=d*100+c*10+b; 38 printf("¸ÃÊýÊÇÈýλÊý£¬ÄæÐòΪ%d\n",e); 39 } 40 else if(a>=10&&a<99) 41 { 42 b=a/10; 43 c=a%10; 44 d=c*10+b; 45 printf("¸ÃÊýÊǶþλÊý£¬ÄæÐòΪ%d\n",d); 46 } 47 else 48 { 49 printf("¸ÃÊýÊÇһλÊý£¬ÄæÐòΪ%d\n",a); 50 } 51 } 52 return 0; 53 }
1、注意判断语句的对应
2、注意计算正确
3、注意输入数值的合法性
4、注意实型常量和整形常量的转换--结论