home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / alb_c10 / chap_06 / ch06_08.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-08  |  1.5 KB  |  75 lines

  1. /*********************************************************************
  2. *  CH06_08.C             Comparaison de fonctions rΘcurrentes *
  3. *                          et non rΘcurrentes *
  4. *********************************************************************/
  5.  
  6. #include<stdio.h>
  7. #include<math.h>
  8.  
  9. int LitInt( void);
  10. void LitDouble( double*);
  11. void ArcTangente1( int, double, double*);
  12. double ArcTangente2( int, double);
  13.  
  14. main( void)
  15. {
  16.     int n;
  17.     double x, arctg1, arctg2;       
  18.  
  19.     printf(" *** Calcul de l'arc dont la tangente est x ***\n");
  20.  
  21.     do
  22.         {
  23.         printf("\n Combien de termes voulez vous calculer: n= ");
  24.         n= LitInt();
  25.     }
  26.     while( n<= 0);
  27.  
  28.         printf("\n Entrez x: ");
  29.         LitDouble( &x);
  30.  
  31.     ArcTangente1( n, x, &arctg1);
  32.     arctg2= ArcTangente2( n, x);
  33.  
  34.     printf("\n Avec %d termes, Arc tg1 %lf= %lf\n\t\t"
  35.                     "  Arc tg2 %lf= %lf",
  36.                      n, x, arctg1, x, arctg2 );
  37. }
  38.  
  39. void ArcTangente1( int q, double v, double *arctg)
  40. {
  41.         int i;
  42.     double a= 0;
  43.  
  44.     for( i= 0; i<= q; i++)
  45.          {
  46.              a+= ( pow( -1, i)* pow( v, 2* i+ 1)/ ( 2* i+ 1));
  47.      }
  48.     *arctg= a;
  49. }
  50.  
  51. double ArcTangente2( int p, double u)
  52. {
  53.     if( p< 0)
  54.         return 0;
  55.          else
  56.         return(   pow( -1, p)* pow( u, 2* p+ 1)/ ( 2* p+ 1)
  57.             + ArcTangente2( p- 1, u) );
  58. }
  59.  
  60. int LitInt( void)
  61. {
  62.     int entier;
  63.     while( scanf("%d", &entier)!= 1)
  64.         while( getchar() != '\n');
  65.     while( getchar() != '\n');
  66.     return ( entier);
  67. }
  68.  
  69. void LitDouble( double *reel)
  70. {
  71.     while( scanf("%lf", reel)!= 1)
  72.         while( getchar() != '\n');
  73.     while( getchar() != '\n');
  74. }
  75.