Multiplication of two complex numbers given as strings | C # program to multiply two complex numbers given as strings . ; Spiting the real and imaginary parts of the given complex strings based on ' + ' and ' i ' symbols . ; Storing the real part of complex string a ; Storing the imaginary part of complex string a ; Storing the real part of complex string b ; Storing the imaginary part of complex string b ; Returns the product . ; Driver code
using System ; using System . Text . RegularExpressions ; class GfG { public static String complexNumberMultiply ( String a , String b ) { String [ ] x = Regex . Split ( a , @"\+ i" ) ; String [ ] y = Regex . Split ( b , @"\+ i" ) ; int a_real = Int32 . Parse ( x [ 0 ] ) ; int a_img = Int32 . Parse ( x [ 1 ] ) ; int b_real = Int32 . Parse ( y [ 0 ] ) ; int b_img = Int32 . Parse ( y [ 1 ] ) ; return ( a_real * b_real - a_img * b_img ) + " + " + ( a_real * b_img + a_img * b_real ) + " i " ; } public static void Main ( String [ ] argc ) { String str1 = "1 + 1i " ; String str2 = "1 + 1i " ; Console . WriteLine ( complexNumberMultiply ( str1 , str2 ) ) ; } }