
给定 n 个点,我们必须根据图表检查该点是否平行于 x 轴或 y 轴或没有轴。图表是用来显示两个变量之间关系的图形,每个变量都沿着直角轴测量。平行是指在所有点上具有相同距离的相同直线,就像铁轨彼此平行一样。
因此,我们必须找出这些点是否平行于 x 轴或 y 轴坐标与轴之间的距离在所有点上都是相同的。
图形是沿着两个轴(x 轴和 y 轴)进行测量的轴的轴从点值 0 开始,并根据其特定的变量值延伸。两个轴组合起来形成一个像直角三角形的图形。
让我们通过一个简单的图示来清楚地理解它 -

下面使用的方法如下 -
Start
In function void parallel (int n, int a[][2])
Step 1-> Declare and initialize i and j
Step 2-> Declare bool x = true, y = true
Step 3-> Loop For i = 0 and i < n – 1 and i++
Loop For j = 0 and j < 2 and j++
If a[i][0] != a[i + 1][0] then,
Set x as false
If a[i][1] != a[i + 1][1] then,
Set y as false
End loop
End loop
Step 4-> If x then,
Print "parallel to X Axis</p><p>"
Step 5-> Else if y
Print "parallel to Y Axis</p><p>"
Step 6-> Else
Print "parallel to X and Y Axis</p><p>"
In function int main()
Step 1-> Declare an array “a[][2]”
Step 2-> Declare and Initialize n as sizeof(a) / sizeof(a[0])
Step 3-> Call function parallel(n, a)#include <stdio.h>
// To check the line is parellel or not
void parallel(int n, int a[][2]) {
int i, j;
bool x = true, y = true;
// checking for parallel to X and Y
// axis condition
for (i = 0; i < n - 1; i++) {
for (j = 0; j < 2; j++) {
if (a[i][0] != a[i + 1][0])
x = false;
if (a[i][1] != a[i + 1][1])
y = false;
}
}
// To display the output
if (x)
printf("parallel to X Axis</p><p>" );
else if (y)
printf("parallel to Y Axis</p><p>" );
else
printf("parallel to X and Y Axis</p><p>" );
}
int main() {
int a[][2] = { { 2, 1 },
{ 3, 1 },
{ 4, 1 },
{ 0, 1 } };
int n = sizeof(a) / sizeof(a[0]);
parallel(n, a);
return 0;
}如果运行上面的代码,它将生成以下输出 -
parallel to Y Axis
以上就是C程序用于检查点是否平行于X轴或Y轴的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号