- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a program to 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)
- Related Articles
- Program to Add Two Complex Numbers in C
- Java Program to Add Two Complex numbers
- Haskell program to add two complex numbers
- Kotlin Program to Add Two Complex numbers
- C++ program to overload addition operator to add two complex numbers
- C++ Program to Add Complex Numbers by Passing Structure to a Function
- How to add two Complex numbers in Golang?
- C++ Program to Add Two Numbers
- How to add two complex numbers by passing structure to a function in C language?
- Add two numbers using ++ operator in C++.
- Python program to add two numbers
- Java Program to Add Two Numbers
- Kotlin Program to Add two Numbers
- Write a Golang program to swap two numbers without using a third variable
- Geometry using Complex Numbers in C++

Advertisements