You are to write a C program that will read from a file, one or more sets of x,y coordinates. Each set of coordinates is part of a Cartesian system. A Cartesian coordinate system is a system that specifies each point uniquely in a plane by a pair of numerical coordinates. Your program will determine which quadrant each set belong. - Quadrants are often numbered 1st - 4th and denoted by Roman numerals: I(+,+), II (−,+), III (−,−), and IV (+,−).
Your program should contain a function that determines and returns which quadrant the x and y coordinate would be in.
Listed below are a few of the steps you will need to take for this program:
Use a C File Pointer (FILE*). The file you will need to open will be defined using a command line argument. You will need to open the file for reading.
You will use fscanf to read each set of coordinates. Once you have read a set of coordinates call the function you wrote to determine the quadrant it belongs in and print the appropriate output.
Below is an example input file.
-1 2
1 2
2 -1
-1 -2
Based on this input file the output would be as follows:
X and Y are in Quadrant II
X and Y are in Quadrant I
X and Y are in Quadrant IV
X and Y are in Quadrant III
Solution:
#include <stdio.h>
int main()
{
int x, y;
printf("Input the Coordinate(x,y): ");
printf("\nx: ");
scanf("%d", &x);
printf("y: ");
scanf("%d", &y);
if(x > 0 && y > 0)
{
printf("Quadrant-I(+,+)\n");
}
else if(x> 0 && y < 0)
{
printf("Quadrant-II(+,-)\n");
}
else if(x < 0 && y < 0)
{ printf("Quadrant-III(-,-)\n");
}
else if(x < 0 && y > 0)
{
printf("Quadrant-IV(-,+)\n");
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.