5.1
#include <stdio.h>
int main(){
char ch1,ch2;
scanf("%c",&ch1);
if((int)ch1>64&&(int)ch1<91){
ch2=ch1+32;
}
else if((int)ch1>96&&(int)ch1<123){
ch2=ch1-32;
}
printf("%c",ch2);
return 0;
}
5.2
#include <stdio.h>
int main(){
char ch1;
scanf("%c",&ch1);
if((int)ch1>65&&(int)ch1<91){
printf("%c %c",ch1-1,ch1+1);
}
if((int)ch1==65){
printf("没有前面的字母");
}
if((int)ch1==91){
printf("没有后面的字母");
}
return 0;
}
5.3
#include <stdio.h>
int main(){
int score;
scanf("%d",&score);
if(score>=90){
printf("A");
}
else if(score>=80&&score<90){
printf("B");
}
else if(score>=70&&score<80){
printf("C");
}
else if(score>=60&&score<70){
printf("D");
}
else{
printf("E");
}
return 0;
}
5.4
#include <stdio.h>
int main(){
int year,month,day;
printf("请输入日期年月日中间用空格隔开,如2020 3 1\n");
scanf("%d %d %d",&year,&month,&day);
if(day==31&&month==12)
year+=1,month=1,day=1;
else if(day==31&&month!=12)
month+=1,day=1;
else if(month==2&&day==29)
month+=1,day=1;
else if(month==2&&day==28)
month+=1,day=1;
else if((month==(2||4||6||9||11))&&day==30)
month+=1,day=1;
else{
day+=1;
}
printf("明天的日期是%d %d %d",year,month,day);
return 0;
}
(这里有个小问题 没有办法判断日期不合法的情况)
5.5
#include <stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a+b>c&&a+c>b&&b+c>a){
if(a==b&&a==c)
printf("等边三角形");
else if(a==b||a==c||c==b)
printf("等腰三角形");
else if(a*a+b*b==c*c||a*a+c*c==b*b||a*a==b*b+c*c)
printf("直角三角形");
else
printf("一般三角形");
}
else
printf("不能构成三角形");
return 0;
}