can any one help!!
write a c program to find addition and subtraction of complex no:s
Answers
Answered by
0
#include <stdio.h>
struct complex {
int real , imag ;
} ;
add_complex (struct complex a , struct complex b, struct complex * c)
{
(*c).real = a.real + b.real;
(*c).imag = a.imag+b.imag;
}
sub_complex(struct complex a, struct complex b, struct complex * c)
{
(*c).real = a.real - b.real;
(*c).imag = a.imag - b.imag;
}
print_complex (struct complex a)
{
printf(" %d ", a.real);
if (a.imag < 0) printf(" - "); else printf(" + ");
printf("%d i ", a.imag);
}
main ()
{
struct complex p, q , r , s;
p.real = 3; p.imag = 5; q.real = 4; q.imag = - 4 ;
add_complex(p, q, & r );
sub_complex(p, q, &s );
printf ("Sum of "); print_complex(p); printf(" and "); print_complex(q); printf(" is = ");
print_complex(r);
printf ("Difference of "); print_complex(p); printf(" and "); print_complex(q); printf(" is = ");
print_complex(s);
}
struct complex {
int real , imag ;
} ;
add_complex (struct complex a , struct complex b, struct complex * c)
{
(*c).real = a.real + b.real;
(*c).imag = a.imag+b.imag;
}
sub_complex(struct complex a, struct complex b, struct complex * c)
{
(*c).real = a.real - b.real;
(*c).imag = a.imag - b.imag;
}
print_complex (struct complex a)
{
printf(" %d ", a.real);
if (a.imag < 0) printf(" - "); else printf(" + ");
printf("%d i ", a.imag);
}
main ()
{
struct complex p, q , r , s;
p.real = 3; p.imag = 5; q.real = 4; q.imag = - 4 ;
add_complex(p, q, & r );
sub_complex(p, q, &s );
printf ("Sum of "); print_complex(p); printf(" and "); print_complex(q); printf(" is = ");
print_complex(r);
printf ("Difference of "); print_complex(p); printf(" and "); print_complex(q); printf(" is = ");
print_complex(s);
}
Similar questions