Cartesian plane
Write a C program to determine the position of a given point (x,y) in a Cartesian plane In This Cartesian Plane,Position of a point can be any of the 4 quadrants, or any of the two axes, or origin. #include<stdio.h> #include<conio.h> //main function int main() { //declaring variables int x, y,ch; clrscr(); printf("This is a program to determine the position of a given point(x,y)\n"); printf("in the cartesian plane\n\n"); //do-while loop do { //taking input from the user printf("Enter the value of x-coordinate: "); scanf("%d", &x); printf("Enter the value of y-coordinate: "); scanf("%d", &y); //determination of the position of the given point if (x == 0) { if (y == 0) printf("The point lie on the origin \n"); else printf("The point lie on the y-axis \n"); } else if (x > 0) { if (y == 0) printf("The point lie on the x-axis \n"); else if (y > 0) printf("The point lie in 1st Quadrant \n"); else printf("The point lie in 4th Quadrant \n"); } else { if (y == 0) printf("The point lie on the x-axis \n"); else if (y > 0) printf("The point lie in 2nd Quadrant \n"); else printf("The point lie in 3rd Quadrant \n"); } printf("do you wish to continue?(0/1)\n"); scanf("%d",&ch); }while(ch==1); getchar(); return 0; } output: This is a program to determine the position of a given point(x,y) in the cartesian plane Enter the value of x-coordinate: 0 Enter the value of y-coordinate: 0 The point lie on the origin do you wish to continue?(0/1) 1 Enter the value of x-coordinate: 0 Enter the value of y-coordinate: 1 The point lie on the y-axis do you wish to continue?(0/1) 1 Enter the value of x-coordinate: 1 Enter the value of y-coordinate: 0 The point lie on the x-axis do you wish to continue?(0/1) 1 Enter the value of x-coordinate: 1 Enter the value of y-coordinate: 1 The point lie in 1st Quadrant do you wish to continue?(0/1) 1 Enter the value of x-coordinate: -3 Enter the value of y-coordinate: 1 The point lie in 2nd Quadrant do you wish to continue?(0/1) 1 Enter the value of x-coordinate: -3 Enter the value of y-coordinate: -2 The point lie in 3rd Quadrant do you wish to continue?(0/1) 1 Enter the value of x-coordinate: 3 Enter the value of y-coordinate: -3 The point lie in 4th Quadrant do you wish to continue?(0/1) 0
Tags:
C Program
0 comments