Guest User

Untitled

a guest
May 24th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.80 KB | None | 0 0
  1. /* cette structure est utilisée dans la foncton d'affichage du resultat de la division euclidienne Affichage_diveucli */
  2. typedef struct
  3. {
  4.     Poly quotient;
  5.     Poly reste;
  6. } QuotientReste ;
  7.  
  8.  
  9.  
  10. /* Division_Euclidienne fait la division euclidienne de  deux polynomes et retourne le resultat sous forme de quotient et reste */
  11. QuotientReste Division_Euclidienne (Poly p1, Poly p2)
  12. {
  13.     tidy_poly(p1);
  14.     tidy_poly(p2);
  15.  
  16.     Poly Q,quotient_final,R,reste_final;
  17.  
  18.     Q = malloc (sizeof (struct p_data));
  19.     quotient_final = NULL;
  20.     quotient_final = Q ;
  21.  
  22.  
  23.     R = malloc (sizeof (struct p_data));
  24.     reste_final = R ;
  25.  
  26.     R->deg= 99 ;
  27.  
  28.     QuotientReste resultat;
  29.     resultat.reste = reste_final ;
  30.     resultat.quotient = quotient_final;
  31.  
  32.     while (R->deg >= p2->deg)
  33.     {
  34.         if (p1->deg >= p2->deg)
  35.         {
  36.  
  37.  
  38.             Q->deg = p1->deg - p2->deg ;
  39.             Q->coef = (p1->coef)/(p2->coef);
  40.  
  41.             R = poly_sub (p1,poly_mult(Q,p2)) ;
  42.  
  43.             Q=Q->red;
  44.             printf("bla");
  45.  
  46.             R = Division_Euclidienne(R,p2).reste;
  47.             Q = Division_Euclidienne(R,p2).quotient;
  48.  
  49.         }
  50.         break;
  51.  
  52.     }
  53.     tidy_poly(quotient_final);
  54.     tidy_poly(reste_final);
  55.     //printf( "Le quotient est:");
  56.     //print_poly(quotient_final);
  57.     //printf("\n.Le reste est:");
  58.     //print_poly(reste_final);
  59.  
  60.     return (resultat) ;
  61. }
  62.  
  63. /* affichage_diveucli prend en parametre le resultat de la division euclidienne de deux polynomes et affiche le reste et le quotient */
  64. void Affichage_diveucli ( QuotientReste q )
  65. {
  66.     Poly reste1,quotient1;
  67.  
  68.     reste1 = q.reste;
  69.     quotient1 = q.quotient;
  70.  
  71.     printf ("Le quotient est :");
  72.     print_poly(quotient1);
  73.     printf ("\n Le reste est: ");
  74.     print_poly(reste1);
  75.     printf ("\n");
  76. }
Add Comment
Please, Sign In to add comment