C/Cpp: Passer un double en paramètre d’une fonction

Author:

 calcul
{filelink=14178}


#include 

/*

calculer la surface d'un cercler

 */

/* Prototype de la fonction */
double calculer_surface(double );

int main(void)
{
  double rayon, surface;

  printf("Tapez le rayon: ");
  scanf("%lf", &rayon);

  printf( "    Surface du cercle nn" );
  printf( "     Rayon          Surfacen"
          "-------------------------n" );

  surface = calculer_surface( rayon );
  printf( "%10.1f     %10.2fn", rayon, surface );

  return 0;
}

/* Calculer la surface d'un cercle */
double calculer_surface( double r )
{
  const double pi = 3.1415926536;    // Pi est un constant
  return  pi * r * r;
}

Leave a Reply

Your email address will not be published. Required fields are marked *