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
using System ; class GFG { static void quadrant ( String s ) { int l = s . Length ; int i ; if ( s . Contains ( " + " ) ) { i = s . IndexOf ( ' + ' ) ; } else { i = s . IndexOf ( ' - ' ) ; } String real = s . Substring ( 0 , i ) ; String imaginary = s . Substring ( i + 1 , l - 2 - i ) ; int x = Int32 . Parse ( real ) ; int y = Int32 . Parse ( imaginary ) ; if ( x > 0 && y > 0 ) Console . Write ( " Quadrant ▁ 1" ) ; else if ( x < 0 && y > 0 ) Console . Write ( " Quadrant ▁ 2" ) ; else if ( x < 0 && y < 0 ) Console . Write ( " Quadrant ▁ 3" ) ; else if ( x > 0 && y < 0 ) Console . Write ( " Quadrant ▁ 4" ) ; else if ( x == 0 && y > 0 ) Console . Write ( " Lies ▁ on ▁ positive " + " ▁ Imaginary ▁ axis " ) ; else if ( x == 0 && y < 0 ) Console . Write ( " Lies ▁ on ▁ negative " + " ▁ Imaginary ▁ axis " ) ; else if ( y == 0 && x < 0 ) Console . Write ( " Lies ▁ on ▁ negative " + " ▁ X - axis " ) ; else if ( y == 0 && x > 0 ) Console . Write ( " Lies ▁ on ▁ positive " + " ▁ X - axis " ) ; else Console . Write ( " Lies ▁ on ▁ the ▁ Origin " ) ; } public static void Main ( String [ ] args ) { String s = "5 + 3i " ; quadrant ( s ) ; } }