/* Exercice I, feuille d'exercices 3 */
/* Melange des solutions proposees */
#include <stdio.h>
#include <assert.h>
#define alloc(a) ((a*)malloc(sizeof(a)))
#define alloctab(a,n) ((a*)malloc((n)*sizeof(a)))
/* A polynomial of degre n is a n+2 array of doubles
The first element represents de degree of the polynomial
If the polynomial is 0, the degree is 0 */
int GetPolynomial (double ** Polynomial_Ptr)
{
int i;
int degre;
printf("Entrez le degre du polynome : ");
scanf("%d",°re);
/* The degree is known, allocate the array accordingly */
*Polynomial_Ptr = alloctab(double,degre+2);
(*Polynomial_Ptr)[0]=degre;
for (i=0 ; i<=degre ; i++)
{
if (i==0)
printf("Donner la constante : ");
else if (i==1)
printf("Donner la constante devant x : ");
else printf("Donner le coefficient devant x^%d : ",i);
scanf("%lf",&((*Polynomial_Ptr)[i+1]));
}
assert(i=degre+1);
}
int PrintPolynomial (double * Polynomial)
{
int i;
int degre;
degre = Polynomial[0];
if (degre>=1)
for (i=degre ; i>=1 ; i--)
printf("%lf x^%d + ",Polynomial[i+1],i);
printf("%lf\n",Polynomial[1]);
}
int main()
{
double * Polynomial;
GetPolynomial(&Polynomial);
PrintPolynomial(Polynomial);
}