Complex Number

Medium Structures & Unions
Solve in Playground →

Problem Statement

Write a C program using a structure to add two complex numbers and print the result.

Input Format

Real and imaginary parts of complex number 1, followed by complex number 2.

Output Format

Print result in format 'Real + Imaginary i'.

Constraints

-1000.0 <= Real, Imag <= 1000.0

Sample Input

3.5 2.5
1.5 4.5

Sample Output

5.00 + 7.00i

Explanation

(3.5 + 2.5i) + (1.5 + 4.5i) = (5.00 + 7.00i).

Starter Code

#include <stdio.h>

struct Complex {
    float real;
    float imag;
};

int main() {
    struct Complex c1, c2;
    if (scanf("%f %f %f %f", &c1.real, &c1.imag, &c2.real, &c2.imag) == 4) {
        // Write your code here
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used