Given n points, we have to check whether the point is parallel to x-axis or y-axis or no axis based on the graph. A graph is a graph used to show the relationship between two variables, each measured along a right-angled axis. Parallel refers to identical straight lines with the same distance at all points, just like railroad tracks that are parallel to each other.
So we have to find out whether the points are parallel to the x-axis or the distance between the y-axis coordinate and the axis is the same at all points.
A graph is an axis measured along two axes (x-axis and y-axis). The axis starts at the point value 0 and extends according to its specific variable value. The two axes combine to form a figure like a right triangle.
Let us understand it clearly with a simple diagram -
The method used below is as follows -
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; }
If you run the above code, it will generate the following output-
parallel to Y Axis
The above is the detailed content of C program to check if a point is parallel to the X-axis or Y-axis. For more information, please follow other related articles on the PHP Chinese website!