#include <stdio.h>
#include <math.h>
struct complex {
double re, imm;
};
typedef struct complex Complex;
Complex leggiC()
{
Complex c;
printf("parte reale ? ");
scanf("%lg", &c.re);
printf("parte immaginaria ? ");
scanf("%lg", &c.imm);
return c;
}
void scriviC(Complex c)
{
if (c.imm < 0)
printf("%4.2f - i*%4.2f", c.re, fabs(c.imm));
else
printf("%4.2f + i*%4.2f", c.re, c.imm);
}
Complex assegnaC(double x, double y)
{
Complex c;
c.re = x;
c.imm = y;
return c;
}
double re(Complex c)
{
return (c.re);
}
double imm(Complex c)
{
return (c.imm);
}
Complex sommaC(Complex c1, Complex c2)
{
Complex c;
c.re = c1.re + c2.re;
c.imm = c1.imm + c2.imm;
return c;
}
Complex prodottoC(Complex c1, Complex c2)
{
Complex c;
c.re = c1.re * c2.re - c1.imm * c2.imm;
c.imm = c1.re * c2.imm + c1.imm * c2.re;
return c;
}
int main(void)
{
Complex a, b, c;
printf("Immetti il primo numero complesso\n");
a = leggiC();
printf("Immetti il secondo numero complesso\n");
b = leggiC();
c = sommaC(a, b);
printf("La somma e`: ");
scriviC(c);
putchar('\n');
c = prodottoC(a, b);
printf("Il prodotto e`: ");
scriviC(c);
putchar('\n');
}