#include /**************************/ /* De'finitions du groupe */ /**************************/ typedef struct complexe { int re; int im; } Complexe; Complexe neutre = {1 , 0}; Complexe mult(Complexe x,Complexe y) { Complexe r; r.re = x.re * y.re - x.im * y.im; r.im = x.re * y.im + x.im * y.re; return r; } Complexe carre(Complexe x) { return mult(x,x); } /***********************/ /* Plus efficace */ /**********************/ /* Complexe carre(Complexe x) { Complexe r; r.re = x.re * x.re - x.im * x.im; r.im = 2 * x.re * x.im return r; } */ Complexe read() { Complexe r; scanf("%d %d",&(r.re),&(r.im)); return r; } void print(Complexe x) { printf("%d",x.re); if (x.im > 0) { printf("+%di",x.im); } else if (x.im < 0) { printf("-%di",-x.im); } } /* Calcul des puissances, cas de la base deux */ typedef Complexe Elem; Elem puissance(Elem x, int n) { int i; Elem t,r; t = x; r = neutre; for (i=n ; i > 0 ; i /= 2) { if (i%2 == 1) { r = mult(r,t); } t = carre(t); } return r; } void main(void) { int n; Elem x; for(;;) { printf("Tapez un complexe :\n"); x = read(); printf("Tapez un entier :\n"); scanf("%d",&n); print(puissance(x,n)); printf("\n\n"); } }