This is a C Program to read a coordinate point in a xy coordinate system and determine its quadrant.

This C Program read a coordinate point in a XY coordinate system and determine its quadrant.

The program accepts X and Y. Depending on the value of X and Y we need to determine on which quadrant this point lies.

Here is source code of the C program to read a coordinate point in a XY coordinate system and determine its quadrant. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/* * C program to accept a coordinate point in a XY coordinate system * and determine its quadrant */ #include <stdio.h> void main() { int x, y; printf("Enter the values for X and Y\n"); scanf("%d %d", &x, &y); if (x > 0 && y > 0) printf("point (%d, %d) lies in the First quandrant\n"); else if (x < 0 && y > 0) printf("point (%d, %d) lies in the Second quandrant\n"); else if (x < 0 && y < 0) printf("point (%d, %d) lies in the Third quandrant\n"); else if (x > 0 && y < 0) printf("point (%d, %d) lies in the Fourth quandrant\n"); else if (x == 0 && y == 0) printf("point (%d, %d) lies at the origin\n"); }

In this C program, we are determining the type of quadrant in XY quadrant system. We are reading the values for ‘X’ and ‘Y’ variable. Nested-if else condition system is used to determine the quadrant of the given value. If conditional statement is used to check the condition that ‘X’ variable value is greater than 0 and the ‘Y’ variable value is greater than 0 using logical AND operator. If the condition is then it will display the output as the first quadrant.

Otherwise, if the condition is false then it will execute the else if conditional statement to check the condition that ‘X’ variable value is less than 0 and the ‘Y’ variable value is greater than 0 using logical AND operator. If the condition is true then it will display the output as the second quadrant.

If the condition is false then it will execute another elseif conditional statement to check the condition that ‘X’ variable value is less than 0 and the ‘Y’ variable value is less than 0 using logical AND operator. If the condition is true then it will display the output as the third quadrant.

Otherwise, if the condition is false then it will execute next elseif conditional statement to check the condition that ‘X’ variable value is greater than 0 and the Y variable value is less than 0 using logical AND operator. If the condition is true then it will display the output as the fourth quadrant.

If the condition is false then it will execute next elseIf statement that the x variable value is equal to 0 and the Y variable value is equal to 0 using logical AND operator, then it will display the output as an origin.

$ cc pgm76.c $ a.out Enter the values for X and Y 20 30 point (-1079549476, -1079549480) lies in the First quandrant $ a.out Enter the values for X and Y -30 -60 point (-1080802740, -1080802744) lies in the Third quandrant $ a.out Enter the values for X and Y 300 -8 point (-1078902004, -1078902008) lies in the Fourth quandrant $ a.out Enter the values for X and Y -180 180 point (-1076456724, -1076456728) lies in the Second quandrant

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

**If you find any mistake above, kindly email to [email protected]**

**Related Posts:**

- Apply for Computer Science Internship
- Check C Books
- Practice BCA MCQs
- Check Computer Science Books
- Apply for C Internship