text: Find the real and imaginary part of a Complex number | C # program to find the real and imaginary parts of a Complex Number ; Function to find real and imaginary parts of a complex number ; string length stored in variable l ; variable for the index of the separator ; Storing the index of ' + ' ; else storing the index of ' - ' ; Finding the real part of the complex number ; Finding the imaginary part of the complex number ; Driver code
code: using System ; class GFG { static void findRealAndImag ( String s ) { int l = s . Length ; int i ; if ( s . IndexOf ( ' + ' ) != - 1 ) { i = s . IndexOf ( ' + ' ) ; } else { i = s . IndexOf ( ' - ' ) ; } String real = s . Substring ( 0 , i ) ; String imaginary = s . Substring ( i + 1 , l - i - 2 ) ; Console . WriteLine ( " Real ▁ part : ▁ " + real ) ; Console . WriteLine ( " Imaginary ▁ part : ▁ " + imaginary ) ; } public static void Main ( String [ ] args ) { String s = "3 + 4i " ; findRealAndImag ( s ) ; } }