- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C Program to check if the points are parallel to X axis or Y axis

Given n number of points we have to check that whether the point is parallel to x-axis or y-axis or no axis according to a graph. A graph is a figure which is used to show a relationship between two variables each measured along with axis at right angles. Parallel are the same lines which are having same distance at all points, like railway tracks are parallel to each other.

So, we have to find whether the points are parallel to x-axis or y-axis means the distance between the coordinates and the axis are same at all points.

## What is an axis

The graph is measured along with two axis’ x-axis and y-axis, both of the axis start from a point value 0 and extend according to their particular variable value. Both of the axis combined form a figure like right angle triangle.

Let’s understand it clearly with help of an simple diagrammatic representation −

**The approach used below is as follows** −

- Firstly we take the coordinates of a graph in way of (x, y) coordinates.
- Then check whether they are parallel to which axis.
- If all y coordinates are same, then the graph is parallel to x-axis.
- Else if the x coordinates are same, then the graph is parallel to y-axis.
- Else the graph is not parallel to either of the axis.

## Algorithm

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\n" Step 5-> Else if y Print "parallel to Y Axis\n" Step 6-> Else Print "parallel to X and Y Axis\n" 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)

## Example

#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\n" ); else if (y) printf("parallel to Y Axis\n" ); else printf("parallel to X and Y Axis\n" ); } 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; }

## Output

If run the above code it will generate the following output −

parallel to Y Axis

- Related Questions & Answers
- Transform the element by using x-axis, y-axis, and z-axis with CSS3
- How to change the range of the X-axis and Y-axis in Matplotlib?
- Transform the element along with x-axis and y-axis with CSS
- How to represent all values of X-axis or Y-axis on the graph in R using ggplot2 package?
- Overlapping Y-axis tick label and X-axis tick label in Matplotlib
- Show the origin axis (x,y) in Matplotlib plot
- How to plot values with log scales on x and y axis or on a single axis in R?
- How to change the scale of Y-axis if the histogram bars are higher than the axis size in R?
- How to join the points of a point chart if X-axis values are categorical in R using ggplot2?
- Create ggplot2 graph with reversed Y-axis and X-axis on top in R.
- Program to check if three points are collinear in C++
- Find Four points such that they form a square whose sides are parallel to x and y axes in C++
- Check if a number can be expressed as x^y (x raised to power y) in C++
- How to customize the X-axis in Matplotlib?
- Find maximum among x^(y^2) or y^(x^2) where x and y are given in C++