Program to determine the Quadrant of a Complex number | C ++ program to determine the quadrant of a complex number ; Function to determine the quadrant of a complex number ; Storing the index of ' + ' ; Storing the index of ' - ' ; Finding the real part of the complex number ; Finding the imaginary part of the complex number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void quadrant ( string s ) { int l = s . length ( ) ; int i ; if ( s . find ( ' + ' ) < l ) { i = s . find ( ' + ' ) ; } else { i = s . find ( ' - ' ) ; } string real = s . substr ( 0 , i ) ; string imaginary = s . substr ( i + 1 , l - 1 ) ; int x = stoi ( real ) ; int y = stoi ( imaginary ) ; if ( x > 0 and y > 0 ) cout << " Quadrant ▁ 1" ; else if ( x < 0 and y > 0 ) cout << " Quadrant ▁ 2" ; else if ( x < 0 and y < 0 ) cout << " Quadrant ▁ 3" ; else if ( x > 0 and y < 0 ) cout << " Quadrant ▁ 4" ; else if ( x == 0 and y > 0 ) cout << " Lies ▁ on ▁ positive " << " ▁ Imaginary ▁ axis " ; else if ( x == 0 and y < 0 ) cout << " Lies ▁ on ▁ negative " << " ▁ Imaginary ▁ axis " ; else if ( y == 0 and x < 0 ) cout << " Lies ▁ on ▁ negative " << " ▁ X - axis " ; else if ( y == 0 and x > 0 ) cout << " Lies ▁ on ▁ positive " << " ▁ X - axis " ; else cout << " Lies ▁ on ▁ the ▁ Origin " ; } int main ( ) { string s = "5 + 3i " ; quadrant ( s ) ; return 0 ; }