在本教程中,我们将讨论查找直线斜率的程序。
为此,我们将在直线上提供两个坐标。我们的任务是找到连接这两个坐标的直线的斜率。
#include <bits/stdc++.h> using namespace std; //查找线的斜率 float slope(float x1, float y1, float x2, float y2) { return (y2 - y1) / (x2 - x1); } int main() { float x1 = 4, y1 = 2; float x2 = 2, y2 = 5; cout << "Slope is: " << slope(x1, y1, x2, y2); return 0; }
输出结果
Slope is: -1.5