w3resource logo
C Programming Exercises

C Exercises: Find the quadrant in which the coordinate point lies

C Conditional Statement: Exercise-9 with Solution

Write a C program to accept a coordinate point in a XY coordinate system and determine in which quadrant the coordinate point lies.

Sample Solution:

C Code:

#include <stdio.h>
void main()
{
	int co1,co2;

	printf("Input the values for X and Y coordinate : ");
	scanf("%d %d",&co1,&co2);

	if( co1 > 0 && co2 > 0)
	  printf("The coordinate point (%d,%d) lies in the First quandrant.\n",co1,co2);
	else if( co1 < 0 && co2 > 0)
	  printf("The coordinate point (%d,%d) lies in the Second quandrant.\n",co1,co2);
	else if( co1 < 0 && co2 < 0)
	  printf("The coordinate point (%d, %d) lies in the Third quandrant.\n",co1,co2);
	else if( co1 > 0 && co2 < 0)
	  printf("The coordinate point (%d,%d) lies in the Fourth quandrant.\n",co1,co2);
	else if( co1 == 0 && co2 == 0)
	  printf("The coordinate point (%d,%d) lies at the origin.\n",co1,co2);

}

Sample Output:

Input the values for X and Y coordinate : 7 9                                                                 
The coordinate point (7,9) lies in the First quandrant. 

Flowchart:

Flowchart: Find the quadrant in which the coordinate point lies.

C Programming Code Editor:

#include <stdio.h>

void main()
{
	int co1,co2;

	printf("Input the values for X and Y coordinate : ");
	scanf("%d %d",&co1,&co2);

	if( co1 > 0 && co2 > 0)
	  printf("The coordinate point (%d,%d) lies in the First quandrant.\n",co1,co2);
	else if( co1 < 0 && co2 > 0)
	  printf("The coordinate point (%d,%d) lies in the Second quandrant.\n",co1,co2);
	else if( co1 < 0 && co2 < 0)
	  printf("The coordinate point (%d, %d) lies in the Third quandrant.\n",co1,co2);
	else if( co1 > 0 && co2 < 0)
	  printf("The coordinate point (%d,%d) lies in the Fourth quandrant.\n",co1,co2);
	else if( co1 == 0 && co2 == 0)
	  printf("The coordinate point (%d,%d) lies at the origin.\n",co1,co2);

}

Improve this sample solution and post your code through Disqus.