bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_1 / assignment-secondary / assignment-s-23.c

assignment-s-23.c (547B)


      1 /* Write a program to add two complex numbers using structures. */
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 struct complex_number
      7 {
      8     double real;
      9     double imaginary;
     10 };
     11 
     12 int main()
     13 {
     14     struct complex_number a, b;
     15     printf("Enter the 1st complex number in this format (a+bi): ");
     16     scanf("%lf+%lfi", &a.real, &a.imaginary);
     17     printf("Enter the 2nd complex number in this format (a+bi): ");
     18     scanf("%lf+%lfi", &b.real, &b.imaginary);
     19 
     20     printf("Result = %-2g + %-2.2g", a.real + b.real, a.imaginary + b.imaginary);
     21     return 0;
     22 }