Exercice langage C corrigé les types float et double

#include
#include
#de?ne N 5
/? type?/
struct cmplx

{ double re;
double im;
};
/? prototypes ?/
struct cmplx lit c(void);
void a?che c(struct cmplx c);
struct cmplx somme c(struct cmplx c1, struct cmplx c2);
struct cmplx produit c(struct cmplx c1, struct cmplx c2);
/? principale ?/
int main()
{ struct cmplx resg,d;
char rep[10];
printf(”gauche ? (deux r´eels a et b pour le complexe a+ ib)\n”);
resg=lit c();
a?che c (resg);
printf(”op? (+ ou? ou r (esultat) )\n”);
scanf(”%s”,rep);
while (rep[0] !=’r’)
{ printf(”droit ? (deux r´eels a et b pour le complexe a+ ib)\n”);
d=lit c();
if (rep[0]==’+’)
{ resg=somme c(resg,d);
}else
{ if (rep[0]==’?’)
{ resg=produit c(resg,d);
}else
{ printf(”erreur\n”);break;
}
}printf(”(interm´ediaire) ==>”);
a?che c (resg);
printf(”op? (+ ou? ou r (esultat) )\n”);
scanf(”%s”,rep);
}printf(”==>”);
a?che c (resg);
return EXIT SUCCESS;
}/?fonctions?/

truct cmplx lit c(void)
{ struct cmplx c;
scanf(”%lf”,&c.re);
scanf(”%lf”,&c.im);
return (c);
}void a?che c(struct cmplx c)
{ printf(”(%lf,%lf)\n”,c.re,c.im);
return ;
}struct cmplx somme c(struct cmplx c1, struct cmplx c2)
{ struct cmplx c;
c.re=c1.re+c2.re;
c.im=c1.im+c2.im;
return (c);
}struct cmplx produit c(struct cmplx c1, struct cmplx c2)
{ struct cmplx c;
c.re=(c1.re?c2.re)?(c1.im?c2.im);
c.im=(c1.re?c2.im)+(c1.im?c2.re);
return (c);
}//((a op b) op c)op d ) etc ...
//[Session started at 2006?11?14 15:45:21 +0100.]
//gauche ? (deux r´eels a et b pour le complexe a+ ib)
//1 1
//(1.000000,1.000000)
//op? (+ ou? ou r (esultat) )
//+
//droit ? (deux r´eels a et b pour le complexe a+ ib)
//3 3
//(interm´ediaire) ==>(4.000000,4.000000)
//op? (+ ou? ou r (esultat) )
//?
//droit ? (deux r´eels a et b pour le complexe a+ ib)
//2 1
//(interm´ediaire) ==>(4.000000,12.000000)
//op? (+ ou? ou r (esultat) )
//r
//==>(4.000000,12.000000)

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *