3.1.比较大小
#include<stdio.h>
int main(void)
{
int a,b,c,max,mid,min;
scanf("%d%d%d",&a,&b,&c);
if(a>b){
if(a>c){
max=a;
if(b>c){
mid=b;
min=c;
}else{
mid=c;
min=b;
}
}else{
max=c;
mid=a;
min=b;
}
}else{
if(b>c){
max=b;
if(a>c){
mid=a;
min=c;
}else{
mid=c;
min=a;
}
}else{
max=c;
mid=b;
min=a;
}
}
printf("Min=%d,Mid=%d,Max=%d",min,mid,max);
return 0;
}
3.2.高速公路超速处罚
#include<stdio.h>
int main(void)
{
double v0=120,v1;
printf("Enter the velocity:");
scanf("%lf",&v1);
if(v1>120*1.5){
printf("您已超过限速50%%,吊销驾驶证");
}else if(v1>120*1.1){
printf("您已超过限速10%%,罚款200");
}else{
printf("当前限速%.0f千米/小时,请小心驾驶",v0);
}
return 0;
}
3.3.出租车计价
#include<stdio.h>
int main(void)
{
double s,q1,q2;
int m;
printf("请输入行驶里程与等待时间:");
scanf("%lf%d",&s,&m);
if(s<=3){
q1=10;
}else if(s>3&&s<=13){
q1=10+(s-3)*2;
}else{
q1=10+20+(s-13)*3;
}
q2=m/5*2;
printf("应支付%lf元",q1+q2);
return 0;
}
3.4.统计学生成绩
#include<stdio.h>
int main(void)
{
int n,i;
double a,b,c,d,e,x;
printf("请输入占总人数和成绩:");
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%lf",&x);
if(x>=90){
a+=1;
}else if(x>=80){
b+=1;
}else if(x>=70){
c+=1;
}else if(x>=60){
d+=1;
}else{
e+=1;
}
}
a/=n;
b/=n;
c/=n;
d/=n;
e/=n;
printf("A:%.1lf%%,B:%.1lf%%,C:%.1lf%%,D:%.1lf%%,E:%.1lf%%",a*100,b*100,c*100,d*100,e*100);
return 0;
}
3.5.三角形判断
#include<stdio.h>
#include<math.h>
int main(void)
{
double x1,x2,x3,y1,y2,y3,area,s,a,b,c;
printf("请输入三个点的横坐标:");
scanf("%lf%lf%lf",&x1,&x2,&x3);
printf("请输入三个点的纵坐标:");
scanf("%lf%lf%lf",&y1,&y2,&y3);
a=sqrt(pow(x2-x3,2)+pow(y2-y3,2));
b=sqrt(pow(x1-x3,2)+pow(y1-y3,2));
c=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
s=(a+b+c)/2;
if(a+b>c&&b+c>a&&c+a>b){
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("三角形面积是%lf",area);
}else{
printf("Impossible");
}
return 0;
}