
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add Two Complex Numbers Using C
Problem
How to add two complex numbers which are entered at run time by the user using C program −
Solution
A complex number is a number that can be a combination of real and imaginary parts.
It is represented in the form of a+ib.
Program
For example, let’s take the two complex numbers as (4+2i) and (5+3i) after adding the two complex numbers, the result is 9+5i.
#include <stdio.h> struct complexNumber{ int realnumber, imaginarynumber; }; int main(){ struct complexNumber x, y, z,p; printf("enter first complex number x and y
"); scanf("%d%d", &x.realnumber, &x.imaginarynumber); printf("enter second complex number z and p
"); scanf("%d%d", &y.realnumber, &y.imaginarynumber); z.realnumber =x.realnumber + y.realnumber; z.imaginarynumber =x.imaginarynumber +y.imaginarynumber; printf("Sum of the complex numbers: (%d) + (%di)
", z.realnumber, z.imaginarynumber); return 0; }
Output
Enter first complex number x and y. 2 3 Enter second complex number z and p. 4 5 Sum of the complex numbers: (6) + (8i)
Advertisements