Complex Number

Medium Structures PRO
🔒 Login to Unlock

Problem Statement

Write a C++ program defining a `Complex` structure (real and imaginary parts) and adding two complex numbers.

Input Format

Real and imaginary parts of Complex 1, followed by Real and imaginary parts of Complex 2.

Output Format

Print resulting complex number in format 'Real + Imaginary i'.

Constraints

-1000 <= Real, Imag <= 1000

Sample Input

3.5 2.0
1.5 4.5

Sample Output

Result: 5.0 + 6.5i

Explanation

Adds real parts together and imaginary parts together using structured data types.

Starter Code

#include <iostream>

struct Complex {
    double real;
    double imag;
};

int main() {
    Complex c1, c2;
    if (std::cin >> c1.real >> c1.imag >> c2.real >> c2.imag) {
        // 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