0% found this document useful (0 votes)
28 views

C++ Complex Numbers Arithmetic

This C++ program defines a struct to represent complex numbers with real and imaginary parts. It includes functions to perform arithmetic operations on complex numbers such as addition, subtraction, multiplication, and division. The main function prompts the user to enter two complex numbers and displays the results of performing each arithmetic operation on the input numbers.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

C++ Complex Numbers Arithmetic

This C++ program defines a struct to represent complex numbers with real and imaginary parts. It includes functions to perform arithmetic operations on complex numbers such as addition, subtraction, multiplication, and division. The main function prompts the user to enter two complex numbers and displays the results of performing each arithmetic operation on the input numbers.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Brandon Perumpail

Complex NUMBERS arithmetic

#include<iostream> using namespace std; struct compl{ double r; double i; }; compl sum (compl a, compl b){ compl z; z.r=a.r+b.r; z.i=a.i+b.i; return z; } compl diff (compl a, compl b){ compl z; z.r=a.r-b.r; z.i=a.i-b.i; return z; } compl prod(compl a, compl b){ compl z; z.i=(a.i*b.i)-(a.r*b.r); z.r=(a.i*b.r)+(a.r*b.i); return z; } compl quot(compl a, compl b){ compl z; compl c; compl d; compl e; c=b; c.r=-1*b.r; d=prod(a,c); e=prod(b,c); z.i=d.i/e.i; z.r=d.r/e.i; return z; } int main () { compl z; compl c; cout<<"Enter the real part of the 1st complex number: "; cin>>z.i; cout<<"Enter the imaginary part of the 1st complex number: "; cin>>z.r; cout<<"\n"; cout<<"Enter the real part of the 2nd complex number: "; cin>>c.i; cout<<"Enter the imaginary part of the 2nd complex number: "; cin>>c.r; cout<<"\n"; compl a=sum(z,c); compl b=diff(z,c); compl d=prod(z,c); compl e=quot(z,c); cout<<"The Sum is:\n"<<"\tThe real part is: "<<a.i<<"\n"<<"\tThe imaginary part is: "<<a.r<<"i \n"; cout<<"The Difference is:\n"<<"\tThe real part is: "<<b.i<<"\n"<<"\tThe imaginary part is: "<<b.r<<"i \n"; cout<<"The Product is:\n"<<"\tThe real part is: "<<d.i<<"\n"<<"\tThe imaginary part is: "<<d.r<<"i \n"; cout<<"The Quotient is:\n"<<"\tThe real part is: "<<e.i<<"\n"<<"\tThe imaginary part is: "<<e.r<<"i"; return 0; }

You might also like