#include <stdio.h>
#include <stdlib.h>
int main()
{
//坐标
int x1,x2,y1,y2;
//斜率未必是整数
float k;
printf("please input x1: ");
scanf("%d",&x1);
printf("please input y1: ");
scanf("%d",&y1);
printf("please input x2: ");
scanf("%d",&x2);
printf("please input y2: ");
scanf("%d",&y2);
//斜率不存在
if(x1-x2==0){
k=0;
}
else{
//强制类型转化
k=(float)(y1-y2)/(x1-x2);
}
//控制输出
printf("The slope is %5.1f",k);
system("pause");
return 0;
}
C语言斜率计算
最新推荐文章于 2025-02-19 20:23:18 发布