bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

P070.c (1026B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 24 Jan 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Write a program to perform addition of two complex number having fields 'real' and 'img'
      9 of type integer. */
     10 
     11 #include <stdio.h>
     12 
     13 struct complex
     14 {
     15     int real;
     16     int img;
     17 };
     18 
     19 void getData(struct complex *c)
     20 {
     21     printf("Enter real: ");
     22     scanf("%d", &c->real);
     23     printf("Enter imaginary: ");
     24     scanf("%d", &c->img);
     25 }
     26 
     27 struct complex add(struct complex c1, struct complex c2)
     28 {
     29     struct complex r;
     30     r.real = c1.real + c2.real;
     31     r.img = c1.img + c2.img;
     32     return r;
     33 }
     34 
     35 void display(struct complex c)
     36 {
     37     printf("%d+%di", c.real, c.img);
     38 }
     39 
     40 int main()
     41 {
     42     struct complex c1, c2, c3;
     43     getData(&c1);
     44     getData(&c2);
     45     printf("\nComplex Number 1:\n");
     46     display(c1);
     47     printf("\nComplex Number 2:\n");
     48     display(c2);
     49     c3 = add(c1, c2);
     50     printf("\nResult: \n");
     51     display(c3);
     52     return 0;
     53 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror