Modulus of a Complex Number | C # program to find the Modulus of a Complex Number ; Function to find modulus 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 ; public class GFG { static void findModulo ( 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 - i - 2 ) ; int x = Int32 . Parse ( real ) ; int y = Int32 . Parse ( imaginary ) ; Console . Write ( Math . Sqrt ( x * x + y * y ) + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { String s = "3 + 4i " ; findModulo ( s ) ; } }