Mathc initiation/001C
Apparence
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 : #10111001
Ce nombre vaut : #10111001 = 185
(1)x**7 + (0)x**6 + (1)x**5 + (1)x**4 + (1)x**3 + (0)x**2 + (0)x +(1) =
2**7 + 2**5 + 2**4 + 2**3 + 1 = 185
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 7
# 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,0,1,1,1,0,0,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 : #10111001\n\n"
" this number is worth : #10111001 = 185\n\n"
" (1)x**7 + (0)x**6 + (1)x**5 + (1)x**4"
" + (1)x**3 + (0)x**2 + (0)x +(1)= 185\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 : #10111001
this number is worth : #10111001 = 185
(1)x**7 + (0)x**6 + (1)x**5 + (1)x**4 + (1)x**3 + (0)x**2 + (0)x +(1)= 185
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**7 + x**5 + x**4 + x**3 +1 = 0
If we divide P(x) by : [x-(+2)]
+1 +0 +1 +1 +1 +0 +0 +1
+0 +2 +4 +10 +22 +46 +92 +184
----------------------------------------------------------------
+1 +2 +5 +11 +23 +46 +92 +185
The synthetic division indicates that P(+2) = +185
Press return to continue.