1.
#include <stdio.h>
int main(){
char a,b,c,d,e;
a=getchar();
b=getchar();
c=getchar();
d=getchar();
e=getchar();
putchar(a);
putchar(b);
putchar(c);
putchar(d);
putchar(e);
putchar('\n');
return 0;
}
2.
#include <stdio.h>
int main(){
int year;
printf("input the year:");
scanf("%d",&year);
if (year%4!=0){
printf("year:%d,month:2,days:28\n",year);
}
else if(year%100!=0){
printf("year:%d,month:2,days:29\n",year);
}
else if(year%400!=0){
printf("year:%d,month:2,days:29\n",year);
}
else {
printf("year:%d,month:2,days:28\n",year);
}
return 0;
}
3.
#include <stdio.h>
int main(){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if((a+b<c)||(a-b>c)){
printf("不能构成三角形\n");
}
else if((a==b)||(b==c)||(c==a)){
printf("此三角形为等腰三角形\n");
}
else if((a==b)&&(b==c)){
printf("此三角形为等边三角形\n");
}
else if((a*a==b*b+c*c)||(b*b==a*a+c*c)||(c*c==b*b+a*a)){
printf("此三角形为直角三角形\n");
}
else{
printf("此三角形为一般三角形\n");
}
return 0;
}
4.
(1)用if~else if语句编程
#include <stdio.h>
int main(){
double a,b,c,d;
scanf("%lf",&a);
if(a<500){
b=0.00;
c=a*b;
d=a*(1-b);
printf("a=%lf,rate=%lf,tax=%lf,profit=%lf\n",a,b,c,d);
}
else if((a>=500)&&(a<1000)){
b=0.05;
c=a*b;
d=a*(1-b);
printf("a=%lf,rate=%lf,tax=%lf,profit=%lf\n",a,b,c,d);
}
else if((a>=1000)&&(a<2000)){
b=0.08;
c=a*b;
d=a*(1-b);
printf("a=%lf,rate=%lf,tax=%lf,profit=%lf\n",a,b,c,d);
}
else if((a>=2000)&&(a<5000)){
b=0.10;
c=a*b;
d=a*(1-b);
printf("a=%lf,rate=%lf,tax=%lf,profit=%lf\n",a,b,c,d);
}
else{
b=0.15;
c=a*b;
d=a*(1-b);
printf("a=%lf,rate=%lf,tax=%lf,profit=%lf\n",a,b,c,d);
}
return 0;
}
(2)用switch语句编程
#include <stdio.h>
int main(){
int e;
double a,b,c,d;
scanf("%lf",&a);
if(a>=5000) e=10;
else e=a/500;
switch(e)
{
case 0: b=0.00;break;
case 1: b=0.05;break;
case 2:
case 3: b=0.08;break;
case 4:
case 5:
case 6:
case 7:
case 8:
case 9: b=0.10;break;
case 10: b=0.15;break;
}
c=a*b;
d=a*(1-b);
printf("a=%lf,rate=%lf,tax=%lf,profit=%lf",a,b,c,d);
return 0;
}