Aller au contenu

Mathc initiation/001B

Un livre de Wikilivres.


Sommaire

Cette méthode permet aussi d'effectuer une conversion rapide d'un nombre écrit en base 2 en écriture en base 10.  Voici un nombre écrit en base 2.

                       Exemple  :  #111                               
                
               Ce nombre vaut   :  #111  =  7                                               
                                 
                       (1) x**2 +  (1) x + (1)   =  7   
                           2**2 +      2 +  1    =  7    
                                                                                                                     
 Il s'agit de l'évaluation d'un polynôme. Le résultat est le reste de la division synthétique.


Installer et compiler ces fichiers dans votre répertoire de travail.

c01a.c
/* ---------------------------------- */
/* save as c01a.c                     */
/* ---------------------------------- */
#include "x_a.h"
/* ---------------------------------- */
# define   DEGREE     2
# define   COEFF_NB   DEGREE + 1
/* ---------------------------------- */
int main(void)
{
double k =  2;
double remainder;

double *Pa  = I_Px( COEFF_NB);
double *Pt  = I_Px( COEFF_NB);
double *Pqr = I_Px( COEFF_NB);
double *Pq  = I_Px((COEFF_NB-1));

double a[COEFF_NB] = {1,1,1};


 clrscrn();
 printf(" Using this method, you can quickly convert\n"
        " a number written in base 2  to base 10.\n\n" 

      " In fact, if a number is written in base 2.\n\n"     
                                                                                          
      "              Example   :  #111\n\n"
                                                                                                  
      " this number is worth   :  #111  =  7\n\n" 

      "         (1)2**2 + (1)(2) + (1)  =  7\n\n"                   
                 
 " This is therefore the evaluation of a polynomial,\n" 
 " it is the remainder of the synthetic division.\n\n\n");
 stop();
 
 clrscrn();
 
 c_a_Px(a,Pa);
 printf("\n If P(x) is : \n\n ");
 p_Px(Pa);printf(" = 0\n\n");

 printf(" If we divide P(x) by : [x-(%+.0f)] \n\n",k);
 remainder = compute_horner(k,Pa,Pt,Pqr,Pq);
 p_horner(Pa,Pt,Pqr);printf("\n");

 printf(" The synthetic division indicates that P(%+.0f) = %+.0f\n\n\n",
        k, remainder);
        
 stop();
 
 free(Pa);
 free(Pt);
 free(Pqr);
 free(Pq);

 return 0;
}
/* ---------------------------------- */
/* ---------------------------------- */


Exemple de sortie écran :

 Using this method, you can quickly convert
 a number written in base 2  to base 10.

 In fact, if a number is written in base 2.

              Example   :  #111

 this number is worth   :  #111  =  7

         (1)2**2 + (1)(2) + (1)  =  7

 This is therefore the evaluation of a polynomial,
 it is the remainder of the synthetic division.


 Press return to continue. 


 If P(x) is : 

 + x**2 + x +1 = 0

 If we divide P(x) by : [x-(+2)] 

      +1      +1      +1   
      +0      +2      +6   
   ------------------------
      +1      +3      +7   


 The synthetic division indicates that P(+2) = +7


 Press return to continue.