w3resource logo


C Programming Exercises

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

Secondary Nav

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.
Test Data :
7 9 
Expected Output :
The coordinate point (7,9) lies in the First quandrant.

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);

}

Flowchart :

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

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.



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables