assignment-s-23.c ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 18 Jan 2026
- License — MIT
Problem Statement ​
Problem Statement
Write a program to add two complex numbers using structures.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <stdlib.h>
struct complex_number
{
double real;
double imaginary;
};
int main()
{
struct complex_number a, b;
printf("Enter the 1st complex number in this format (a+bi): ");
scanf("%lf+%lfi", &a.real, &a.imaginary);
printf("Enter the 2nd complex number in this format (a+bi): ");
scanf("%lf+%lfi", &b.real, &b.imaginary);
printf("Result = %-2g + %-2.2g", a.real + b.real, a.imaginary + b.imaginary);
return 0;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20