Hi, I need a little help modifying more for this program.
Instructions:(Menu based program)
Complex Number Menu
1. input complex number 1
2. input complex number 2
3. add
4. subtract
5. magnitude of a complex number
6. angle of a complex number
7. display complex numbers
8. exit
#include <stdio.h>
#include <stdlib.h>
typedefstruct complex
{
float real;
float imag;
} complex_t;
complex_t add_complex(complex_t a, complex_t b)
{
complex_t temp;
temp.real = a.real + b.real;
temp.imag = a.imag + b.imag;
return temp;
}
// prints values of a complex number
void print_complex(complex_t a);
// defines a complex value by supplying the real and imag values
complex_t complex(float a, float b);
int main()
{
complex_t x={1,-2},y,z;
y = complex(-1,-2);
print_complex(y); // print the values of y
print_complex(x); // print the values of x
z = add_complex(y,x); // add x and y and put result into z
print_complex(z); // print the values z
}
void print_complex(complex_t a)
{
printf("\n%f ",a.real);
// this if-else takes care of the sign when printing
// so that the - is place before j for negative values
if (a.imag<0) printf("-j%f\n",-a.imag);
else printf("+j%f\n",a.imag);
}
// note that this function returns a complex type
complex_t complex(float a, float b)
{
complex_t temp;
temp.real = a;
temp.imag = b;
return temp;
}