Aller au contenu

Mathc initiation/Fichiers c : c15n

Un livre de Wikilivres.


Sommaire


Installer ce fichier dans votre répertoire de travail.

x_hprint.h
utilitaire
/* ---------------------------------- */
/* save as x_hprint.h                 */
/* ---------------------------------- */
void  p_Px(
double *Px)
{
   int c       = 1;
   int Px_NULL = TRUE;
   int degree  = Px[0]-1;

double coeff   = 0.;

for (c=1; c<Px[0]; c++)
{      
 coeff = Px[c];

 --degree;

 if(coeff)
 {
  Px_NULL = FALSE;
  if(degree)
  {
   if(degree==1)
     {
           if(coeff ==  1)     printf("+ x ");
      else if(coeff == -1)     printf("- x ");
      else                     printf("%+.0fx ",coeff);
      }
   else
     {
           if(coeff ==  1)     printf("+ x**%d ",          degree);
      else if(coeff == -1)     printf("- x**%d ",          degree);
      else                     printf("%+.0fx**%d ",coeff,degree);
      }
  }
  else printf("%+.0f",coeff);
 }
}

 if(Px_NULL){printf("  0");}
}
/* ---------------------------------- */
/* ---------------------------------- */


La fonction imprime un polynôme.