English

Write a program to input two complex numbers and to find sum of the given complex numbers.

Advertisements
Advertisements

Question

Write a program to input two complex numbers and to find sum of the given complex numbers.

Code Writing
Advertisements

Solution

Add the real parts and add the imaginary parts of the two complex numbers.

real1 = int(input("Enter real part of first complex number: "))
imag1 = int(input("Enter imaginary part of first complex number: "))
real2 = int(input("Enter real part of second complex number: "))
imag2 = int(input("Enter imaginary part of second complex number: "))

real_sum = real1 + real2
imag_sum = imag1 + imag2

print("Sum =", real_sum, "+", imag_sum, "i")
shaalaa.com
  Is there an error in this question or solution?
Chapter 1: Review of Phython - EXERCISE [Page 27]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 1 Review of Phython
EXERCISE | Q 16. | Page 27
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×