SnapTimes

News In A Snap!!

C++ Programs: Add/Subtract Complex Numbers

April 8, 2015

C++_Main

 What is a Complex Number?

A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers and i is the imaginary unit, that satisfies the equation x2 = −1, that is, i2 = −1. In this expression, a is the real part and b is the imaginary part of the complex number.

Code


// Program to add/subtract complex numbers

#include <iostream.h>
 #include<conio.h>

int main() {

clrscr();
 int a, b, c, d;
  
 cout << "Program to add two complex numbers" << endl;
 cout << endl << "Enter first number a+bi" << endl;
 cout << "Enter value for a: ";
 cin >> a;
 cout << "Enter value for b: ";
 cin >> b;
 cout << endl << "Enter second number c+di" << endl;
 cout << "Enter value for c: ";
 cin >> c;
 cout << "Enter value for d: ";
 cin >> d;
 cout << endl << "Result of addition: ";
 cout << (a+c);
 cout << ((b+d)>0 ? "+" : "");
 cout << (b+d) << "i" << endl;
 cout << endl << "Result of subtraction: ";
 cout << (a-c);
 cout << (((b-d)>0) ? "+" : "");
 cout << (b-d) << "i" << endl;
 getch();
 }

Output:cn


SnapTimes.in | Get Tech Addicted...
About Us | Contact Us | ©2017