42 lines
737 B
C
42 lines
737 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
struct imaginaire {
|
|
int x;
|
|
int y;
|
|
};
|
|
|
|
struct imaginaire conjugue(struct imaginaire z) {
|
|
struct imaginaire z_conjugue;
|
|
z_conjugue.x = z.x;
|
|
z_conjugue.y = z.y * -1;
|
|
return z_conjugue;
|
|
}
|
|
|
|
double module(struct imaginaire z) {
|
|
return sqrt((z.x*z.x) + (z.y*z.y));
|
|
}
|
|
|
|
void afficher_imaginaire(struct imaginaire z) {
|
|
if (z.y < 0) {
|
|
printf("%d - %di", z.x, z.y*-1);
|
|
}
|
|
else {
|
|
printf("%d + %di", z.x, z.y);
|
|
}
|
|
putchar('\n');
|
|
}
|
|
|
|
void inverse(struct imaginaire z) {
|
|
printf("1 / ");
|
|
afficher_imaginaire(z);
|
|
}
|
|
|
|
int main (void) {
|
|
struct imaginaire test = {4, 8};
|
|
afficher_imaginaire(test);
|
|
afficher_imaginaire(conjugue(test));
|
|
printf("%f\n",module(test));
|
|
inverse(test);
|
|
} |