home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / alb_c10 / chap_06 / ch06_07.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-27  |  887 b   |  44 lines

  1. /*********************************************************************
  2. *  CH06_07.C                             RΘcurrence des fonctions  *
  3. *********************************************************************/
  4.  
  5. #include<stdio.h>
  6.  
  7. int LitInt( void);
  8. unsigned long int SommeSerie( int);
  9.  
  10. main( void)
  11. {
  12.  
  13.     int n;
  14.  
  15.         printf(" *** Calcul de la somme des n premiers entiers ***\n");
  16.  
  17.     do
  18.         {
  19.         printf("\n Entrez n: ");
  20.         n= LitInt();
  21.     }
  22.     while( n<= 0);
  23.  
  24.     printf(" La somme des termes: S( %d)= %lu",
  25.                         n, SommeSerie( n));
  26. }
  27.  
  28. unsigned long int SommeSerie( int p)
  29. {
  30.     if( p<= 0)
  31.         return 0;    /* c'est aussi la condition d'arrΩt.   */
  32.         else
  33.         return( p+ Somme_Serie( p- 1));
  34. }
  35.  
  36. int LitInt( void)
  37. {
  38.         int Entier;
  39.     while( scanf("%d", &Entier)!= 1)
  40.         while( getchar() != '\n');
  41.     while( getchar() != '\n');
  42.     return ( Entier);
  43. }
  44.