Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct complex
- {
- float real;
- float imag;
- };
- int main()
- {
- struct complex cplx = {6, 5};
- print_cplx(cplx);
- return 0;
- }
- float cplx_real(struct complex cplx)
- {
- return cplx.real;
- }
- float cplx_imag(struct complex cplx)
- {
- return cplx.imag;
- }
- struct complex cplx_conj(struct complex cplx)
- {
- cplx.imag = -cplx.imag;
- return cplx;
- }
- void print_cplx(struct complex cplx)
- {
- printf("%.4f + %.4fi", cplx.real, cplx.imag);
- }
- struct complex cplx_add(const struct complex cplx1, const struct complex cplx2)
- {
- struct complex cplx = {cplx1.real+cplx2.real, cplx1.imag+cplx2.imag};
- return cplx;
- }
- struct complex cplx_sub(const struct complex cplx1, const struct complex cplx2)
- {
- struct complex cplx = {cplx1.real-cplx2.real, cplx1.imag-cplx2.imag};
- return cplx;
- }
- struct complex cplx_nul(const struct complex cplx1, const struct complex cplx2)
- {
- struct complex cplx = {cplx1.real*cplx2.real, cplx1.imag*cplx2.imag};
- return cplx;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement