1: 0
2: 20
3: (x<30&&x>20)||(x<-100)
4: ***a=25,b=14,c=16***
5: 37
6: if(a<=b) printf("1");
else printf("2");
7、
#include<stdio.h>
void main()
{ char a,b,t1,t2;
scanf("%c,%c",&a,&b);
t1=a>b?a:b;
t2=a<b?a:b;
if((t1-t2)%2==0)printf("%c,%c",a+1,b+1);
else printf("%c,%c",a-1,b-1);
getch();
}
8、
#include<stdio.h>
void main()
{ int temp1=0,temp2=0,x,y,i=1;
printf("Please input (x,y): ");
scanf("%d,%d",&x,&y);
while((i*y)<=x)
{ if(x==(i*y)) {temp1=1;break;}
temp2=i;
i++;
}
if(temp1)
printf("%d / %d = %d",x,y,i);
else
printf("%d / %d---> shang=%d,yushu=%d",x,y,temp2,x-y*temp2);
getch();
}
9、
#include<stdio.h>
void main()
{ float x,y,m=0,n=0;
scanf("%f,%f",&x,&y);
n=(x-2)*(x-2);
m=(y-2)*(y-2);
if((m+n)<=1)
printf("(%.3f,%.3f)In the yuan",x,y);
else
printf("(%.3f,%.3f)out of the yuan",x,y);
getch();
}
10、
#include<stdio.h>
void main()
{ int temp=0,month,year;
printf("Please input (year,month): ");
scanf("%d,%d",&year,&month);
if((year%400==0)||(year%4==0&&year%100!=0))
temp=1;
if(month==2)
{ if(temp)printf("%d year %d month have 29 ",year,month);
else printf("%d year %d month have 28 ",year,month);
}
else if(month%2==0)
printf("%d year %d month have 30 ",year,month);
else printf("%d year %d month have 31 ",year,month);
getch();
}
11、
switch(a/10)
{ case 5:m=4;break;
case 4:m=3;break;
case 3:m=2;break;
case 2:m=1;break;
default:m=5;
}
12、
方法一:
#include<stdio.h>
void main()
{ int x,y;
scanf("%d",&x);
if(x<0&&x>-5)
y=x-1;
else if(x==0)
y=x;
else if(x>0&&x<8)
y=x+1;
printf("%d",y);
getch();
}
方法二:
#include<stdio.h>
void main()
{ int x,y;
scanf("%d",&x);
if(x<8&&x>-5)
{ if(x==0)y=x;
else if(x>0&&x<8) y=y=x+1;
else y=x-1;
printf("%d",y);
}
else printf("Input error!!!");
getch();
}
方法三:
#include<stdio.h>
void main()
{ int x,y,i;
scanf("%d",&x);
if(x<8&&x>-5)
{ if(x==0)i=1;
else if(x>0&&x<8) i=2;
else i=3;
}
else i=4;
switch(i)
{ case 1:y=x;printf("%d",y);break;
case 2:y=x+1;printf("%d",y);break;
case 3:y=x-1;printf("%d",y);break;
case 4:printf("Input error!!");break;
}getch();
}