首页 > 代码库 > 第五次作业

第五次作业

#include<stdio.h>
int main()//1.比较三个数大小(从小到大排序)
{ 
    int a,b,c,d=0;
    printf("请输入三个数\n");
    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;
}
printf("%d < %d < %d",a,b,c);
}
#include<stdio.h>
int main()//2.高速公路限速处罚
{
    int x,z;
    scanf("%d %d",&x,&z);
    double b = (double)(x-z)*100/z;
    if (b>50)printf("超过限速 %.0f%%. 吊销执照",b);
    if(b>=10&&b<=50)printf("超出限速 %.0f%%. 罚款 200",b);
    if(b<10)printf("未超过限速");
}

#include <stdio>
using namespace std;//3.出租车计费 

int count(double miles);

int main(){
int x;double wait;
cout<<"输入公里"<<endl;
cin>>x;
cout<<"等待时间"<<endl;
cin>>wait;
cout<<count(x+int(wait/5));
return(0);
}

int count(double x){//TODO:
if (x<0) {cout<<"不可能"<<endl; return 0;}
double t=0;
if (x<3) {
t=10;
}else{
t+=10;
if (x>13) {
t+=20+3*(x-13);
}else{
t+=2*(x-3);
}
}

return int(t+0.5);
}




#include <stdio.h>
int main()//4.五级制成绩分布 
{
    int i,A,B,C,D,E,n,s;
    A=B=C=D=E=0;
    printf("Enter n:");
    scanf("%d",&n);
    for(i=0;i<n;++i)
    {
        printf("Enter grade %d:",i+1);
        scanf("%d",&s);
        switch(s/10)
        {
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:E++;break;
        case 6:D++;break;
        case 7:C++;break;
        case 8:B++;break;
        case 9:
        case 10:A++;break;
        }
    }
    printf("The number of A(90~100):%d\n",A);
    printf("The number of B(80~89):%d\n",B);
    printf("The number of C(70~79):%d\n",C);
    printf("The number of D(60~69):%d\n",D);
    printf("The number of E(0~59):%d\n",E);
    return 0;
}



#include<stdio.h>
#include<stdio.h>
 
int main()//5.判断三角形
{ double a,b,c,d,e,f;
  scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f );
  double AB,BC,AC,ab,bc,ac;
  ab=(a-c)*(a-c)+(b-d)*(b-d);
  bc=(c-e)*(c-e)+(d-f)*(d-f);
  ac=(a-e)*(a-e)+(b-f)*(b-f);
  AB=sqrt(ab);
  BC=sqrt(bc);
  AC=sqrt(ac);
  if((AB<BC+AC)&&(BC<AB+AC)&&(AC<AB+BC))
  {
  double l=AB+BC+AC;
  double P = l / 2;
  double s = sqrt(P*(P-AB)*(P-BC)*(P-AC));
  printf("L = %.2f, A = %.2f",l,s); }
  else
  {printf ("Impossible");
  }
  return 0;
}


#include<stdio.h>
int main()//6.双循环打印三角形 
{
    int i,j;
    for(j=1;j<=10;j++)
    {
        for(i=1;i<=11-j;i++)
        {
            printf("*");
        }
        printf("\n");
    }
}

第五次作业