#include #include #include struct complexe { float reel; float imaginaire; }; typedef struct complexe complexe; float norme ( complexe * C ); complexe * newcomplexe (float i, float t) ; void afficher (complexe * C); complexe * add (complexe * C,complexe * T); complexe * multiply ( complexe * C , complexe * T ); int compare ( float t , float k ); complexe * compare2(complexe * C , complexe * D ); complexe * tridanstableau(complexe* U[], int t); main() { complexe * R = NULL; complexe * T = NULL; complexe * Z = NULL; complexe * K = NULL; R = newcomplexe(5.0,2.0); T = newcomplexe(1.0,4.5); Z = add(R,T); K = multiply(R,T); complexe * tab[4] = {R,T,Z,K}; printf("R = "); afficher(R); printf("T = "); afficher(T); printf("Z (addition des 2) = "); afficher(Z); printf("K (multiplication des 2) = "); afficher(K); printf("Norme de R = %g\n",norme(R)); printf("Norme de T = %g\n",norme(T)); printf("Plus grande des 2 normes = %g\n",compare(norme(R), norme(T))); printf("Plus grand dans tableau = "); afficher(tridanstableau(tab,4)); free(R); free(T); free(Z); free(K); } complexe * newcomplexe (float i, float t) { complexe * R = NULL; R = malloc(sizeof(complexe)); if (R == NULL) { error(4); return R; } (*(R)).reel = i; (*(R)).imaginaire = t; return R; } void afficher (complexe * C) { printf("%g + %gi\n",(*C).reel,(*C).imaginaire); } complexe * add (complexe * C,complexe * T) { complexe * R = NULL; R = malloc(sizeof(complexe)); if (R == NULL) { error(5); return R; } (*R).reel = (*C).reel + (*T).reel; (*R).imaginaire = (*C).imaginaire + (*T).imaginaire; return R; } complexe * multiply ( complexe * C , complexe * T ) { complexe * R = NULL; R = malloc(sizeof(complexe)); if (R==NULL) { error(6); return R; } (*(R)).reel = (*(C)).reel * (*(T)).reel - (*(C)).imaginaire * (*(T)).imaginaire; (*(R)).imaginaire = (*(C)).imaginaire * (*(T)).reel + (*(T)).imaginaire * (*(C)).reel; return R; } float norme ( complexe * C ) { float k; k = sqrt(pow((*(C)).reel,2) + pow((*(C)).imaginaire,2)); return k; } int compare ( float t , float k ) { if ( t > k ) { return 1 ;} else { return 0; } } complexe * compare2(complexe * C , complexe * D ) { int c; c = compare(norme(C),norme(D)); if (c) { return C; } else { return D; } } complexe * tridanstableau(complexe* U[], int t) { int k = 0; complexe * T; for(k = 0;k