实验二

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(' ');

 return 0;

}

2.

#include<stdio.h>
int main()
{
 int a,b;
 b=0;
 printf("input the year");
 scanf("%d",&a);
 if(a%400==0)
 {
  b=1;
 }
 if(a%4==0)
 {if(a%100!=0)
  {b=1;
  }
 }
 if(b==1)
 {printf("year:%d,month:2,days:29 ",a);
 }
 else
 {printf("year:%d,month:2,days:28 ",a);
 }
 return 0;
}

3.

#include<stdio.h>

int main() { int a,b,c,d,e,f;

scanf("%d%d%d",&a,&b,&c); if(a<b) {d=a;  a=b;  b=d; }

if(b<c) {d=b;  b=c;  c=d; } if(a<b) {d=a;  a=b;  b=d; } d=b+c; e=b*b+c*c; f=a*a; if(d>a) {  if(a==c)  {printf("为等边三角形");}  else if(a==b || b==c)   {if(f==e)    {printf("为等腰直角三角形");}   else   {printf("为等腰三角形");}  }  else if(f==e)   {printf("为直角三角形");  }  else   printf("为一般三角形"); } else {printf("不是三角形");} return 0; }

4.

第一种

#include<stdio.h>

int main() { double a,r,tax,profit; scanf("%lf",&a); if(a<500) {r=0.00;} else if(a<1000) {r=0.05;} else if(a<2000) {r=0.08;} else if(a<5000) {r=0.10;} else {r=0.15;} tax=a*r; profit=a-tax; printf("a=%lf rate=%lf tax=%lf profit=%lf",a,r,tax,profit); }

第二种

#include<stdio.h>

int main() { double a,r,tax,profit; int k; scanf("%lf",&a); if(a<500) {k=1;} else if(a<1000) {k=2;} else if(a<2000) {k=3;} else if(a<5000) {k=4;} else {k=5;} switch(k) { case 1: r=0.00;break; case 2:r=0.05;break;

case 3:r=0.08;break;

case 4:r=0.10;break; case 5:r=0.15;break; } tax=a*r; profit=a-tax; printf("a=%lf rate=%lf tax=%lf profit=%lf",a,r,tax,profit); return 0; }

原文地址:https://www.cnblogs.com/P201821430046/p/10769160.html