C++ program to find the Quadrant in which Coordinates lie

Program to find the Quadrant in which Coordinates lie

  • If both the coordinates are positive then the coordinates lie in the 1st quadrant
  • if x coordinate is negative and the y coordinate is positive then the coordinates lie in the 2nd quadrant. 
  • If both are negative then the coordinates lie in the 3rd quadrant.
  • if y coordinate is negative and the x coordinate is positive then the coordinates lie in the 4th quadrant.
  • If the x coordinate is 0 then the coordinates lie on the y axis.
  • If the y coordinate is 0 then the coordinates lie on the x axis.
  • If both are zero then they lie on the origin.

To find the quadrants we will be using if else statements.

program to find the quadrant in which coordinate lies

Algorithm:-

  1. User gives two inputs(x & y coordinates).
  2. The inputs are stored in two int type variables say x & y.
  3. If x is equal to 0 then the coordinates lie on the y axis.

             if(x==0)

      4. If y is equal to 0 then the coordinates lie on the x axis.

            else if(y==0)

       5. If x & y are positive then the coordinates lie in the 1st quadrant.

            else if(x>0&&y>0)

       6. If x is negative and y is positive then the coordinates lie in the 2nd quadrant.

            else if(x<0&&y>0)

       7. If x & y are negative then the coordinates lie in the 3rd quadrant.

            else if(x<0&&y<0)

       8. If x is positive and y is positive then the coordinates lie in the 4th quadrant.

            else if(x>0&&y<0)

       9. Otherwise the coordinate lies on the origin.

C++ Code:-

    
    //C++ program
    //Quadrants in which coordinates lie
    #include<iostream>
    using namespace std;
    //main program
    int main()
    {
        int xy;
        cout<<“Enter coordinates: \n;
        cin>>x>>y;
        //checking for quadrants and axis
        if(x==0)
            cout<<x<<“,”<<y<<” lies on y axis”;
        else if(y==0)
            cout<<x<<“,”<<y<<” lies on x axis”;
        else if(x>0&&y>0)
            cout<<x<<“,”<<y<<” lies in 1st quadrant”;
        else if(x<0&&y>0)
            cout<<x<<“,”<<y<<” lies in 2nd quadrant”;
        else if(x<0&&y<0)
            cout<<x<<“,”<<y<<” lies in 3rd quadrant”;
        else if(x>0&&y<0)
            cout<<x<<“,”<<y<<” lies in 4th quadrant”;
        else
            cout<<x<<“,”<<y<<” lies on the origin”;
        return 0;   
    }

    Output

    Enter coordinates: 
    1
    –8
    1,-8 lies in 4th quadrant
coding (3)
  • Highest Common Factor(HCF): C | C++Java | Python
  • Lowest Common Multiple (LCM) : C | C++ | Java | Python
  • Greatest Common Divisor : C | C++ | Java | Python
  • Binary to Decimal to conversion : C | C++ | Java | Python
  • Binary to Octal conversion : C | C++ | Java  | Python
  • Decimal to Binary conversion: C | C++ | Java | Python
  • Decimal to octal Conversion: C | C++ | Java | Python
  • Octal to Binary conversion : C | C++ | Java | Python
  • Octal to Decimal conversion : C | C++ | Java | Python
  • Quadrants in which a given coordinate lies : C | C++ | Java | Python
  • Permutations in which n people can occupy r seats in a classroom : C | C++ | Java | Python
  • Maximum number of handshakes: C | C++ | Java | Python
  • Addition of two fractions: C | C++ | Java | Python
  • Replace all 0’s with 1 in a given integer : C | C++ | Java | Python
  • Can a number be expressed as a sum of two prime numbers : C | C++ | Java | Python
  • Count possible decoding of a given digit sequence : C | C++ | Java
  • Check whether a character is a vowel or consonant : C | C++ | Java | Python
  • Check whether a character is a alphabet or not : C | C++ | Java | Python
  • Calculate the area of a circle : C | C++ | Java | Python
  • Find the ASCII value of a character : C | C++ | Java | Python
  • Find the prime numbers between 1 to 100 : C | C++ | Java | Python
  • Calculate the number of digits in an integer : C | C++ | Java | Python
  • Convert digit/number to words : C | C++ | Java | Python
  • Counting number of days in a given month of a year: C | C++ | Java | Python
  • Finding Number of times x digit occurs in a given input : C | C++ | Java | Python
  • Finding number of integers which has exactly x divisors: C | C++ | Java | Python
  • Finding Roots of a quadratic equation : C | C++ | Java | Python