`{"id":"8e7ec41f-d2bd-4173-a9dc-c6eb6a2c03b7","name":"Complex Number Multiplication","description":"1. A complex number can be represented as a string on the form \"Real + Imaginary i\" where:\r\n 1.1 Real is the real part and is an integer in the range [-100, 100].\r\n 1.2 Imaginary is the imaginary part and is an integer in the range [-100, 100].\r\n 1.3 i^2 == -1.\r\n2. Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.\r\n","inputFormat":"1. num1 = \"1+1i\", num2 = \"1+1i\"\r\n2. num1 = \"1+-1i\", num2 = \"1+-1i\"\r\n","outputFormat":"1. \"0+2i\"\r\nExplanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.\r\n","constraints":"num1 and num2 are valid complex numbers.\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nstring complexNumberMultiply(string num1, string num2) {\n //write your code here\n}\n\nint main(){\n string num1, num2;\n cin>>num1>>num2;\n \n string res = complexNumberMultiply(num1, num2);\n cout<<res;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~User''s Section~~~~~~~~~~~~~\r\n public static String complexNumberMultiply(String num1, String num2) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~~Input Management~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n String num1 = scn.nextLine();\r\n String num2 = scn.nextLine();\r\n String res = complexNumberMultiply(num1, num2);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1+1i\r\n1+1i","sampleOutput":"0+2i","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"a9c959e0-e1db-4d02-bfa3-96d9dfa37002","name":"Complex Number Multiplication","slug":"complex-number-multiplication","type":1}],"next":{"id":"97a29272-e8d3-4216-bbf0-76004f0b09f2","name":"Complex Number Multiplication","type":3,"slug":"complex-number-multiplication"},"prev":{"id":"0454f2de-cb6f-4b66-9824-73e461c61b2b","name":"Sort Array By Parity MCQ","type":0,"slug":"sort-array-by-parity-mcq"}}}`

# Complex Number Multiplication

1. A complex number can be represented as a string on the form "Real + Imaginary i" where: 1.1 Real is the real part and is an integer in the range [-100, 100]. 1.2 Imaginary is the imaginary part and is an integer in the range [-100, 100]. 1.3 i^2 == -1. 2. Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.

`{"id":"8e7ec41f-d2bd-4173-a9dc-c6eb6a2c03b7","name":"Complex Number Multiplication","description":"1. A complex number can be represented as a string on the form \"Real + Imaginary i\" where:\r\n 1.1 Real is the real part and is an integer in the range [-100, 100].\r\n 1.2 Imaginary is the imaginary part and is an integer in the range [-100, 100].\r\n 1.3 i^2 == -1.\r\n2. Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.\r\n","inputFormat":"1. num1 = \"1+1i\", num2 = \"1+1i\"\r\n2. num1 = \"1+-1i\", num2 = \"1+-1i\"\r\n","outputFormat":"1. \"0+2i\"\r\nExplanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.\r\n","constraints":"num1 and num2 are valid complex numbers.\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nstring complexNumberMultiply(string num1, string num2) {\n //write your code here\n}\n\nint main(){\n string num1, num2;\n cin>>num1>>num2;\n \n string res = complexNumberMultiply(num1, num2);\n cout<<res;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~User''s Section~~~~~~~~~~~~~\r\n public static String complexNumberMultiply(String num1, String num2) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~~Input Management~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n String num1 = scn.nextLine();\r\n String num2 = scn.nextLine();\r\n String res = complexNumberMultiply(num1, num2);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1+1i\r\n1+1i","sampleOutput":"0+2i","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"a9c959e0-e1db-4d02-bfa3-96d9dfa37002","name":"Complex Number Multiplication","slug":"complex-number-multiplication","type":1}],"next":{"id":"97a29272-e8d3-4216-bbf0-76004f0b09f2","name":"Complex Number Multiplication","type":3,"slug":"complex-number-multiplication"},"prev":{"id":"0454f2de-cb6f-4b66-9824-73e461c61b2b","name":"Sort Array By Parity MCQ","type":0,"slug":"sort-array-by-parity-mcq"}}}` Editor

# Complex Number Multiplication

easy

1. A complex number can be represented as a string on the form "Real + Imaginary i" where: 1.1 Real is the real part and is an integer in the range [-100, 100]. 1.2 Imaginary is the imaginary part and is an integer in the range [-100, 100]. 1.3 i^2 == -1. 2. Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.

## Constraints

num1 and num2 are valid complex numbers.

## Format

### Input

1. num1 = "1+1i", num2 = "1+1i" 2. num1 = "1+-1i", num2 = "1+-1i"

### Output

1. "0+2i" Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}1+1i 1+1i```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}0+2i`

Discussions

Show Discussion

Related Resources 