home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_01_01
/
1n01079b
< prev
next >
Wrap
Text File
|
1990-05-17
|
722b
|
42 lines
#include "stdio.h"
struct complex
{
double real, imag;
};
struct complex cplx_add(struct complex * a, struct complex * b);
int cplx_print(struct complex * c);
int main()
{
struct complex c1, c2, c3;
c1.real = 1.5;
c1.imag = 0.0;
c2.real = 7.1;
c2.imag = 8.0;
c3 = cplx_add(&c1,&c2);
cplx_print(&c3);
return 0;
}
struct complex cplx_add(struct complex * a, struct complex * b)
{
struct complex result;
result.real = a->real + b->real;
result.imag = a->imag + b->imag;
return result;
}
int cplx_print(struct complex * c)
{
return printf("(%g%+gi)",c->real,c->imag);
}