Entrainements + fin TP structures
This commit is contained in:
42
DEV1.1/TP20/tests.c
Normal file
42
DEV1.1/TP20/tests.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#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);
|
||||
}
|
Reference in New Issue
Block a user