2008年9月30日 星期二

程式語言10/1

#include /* Standard Input/Output function declarations */ #include /* Math functions, such as sqrt(x), and constant M_PI */ #include
int main( void ) { float fRadius; /* Radius of circle */ float fArea; /* Area of circle */ float fPi; /* Variable for "pi" */
/* [a] : Prompt User for "radius of circle" */
printf("============================================\n"); printf("Please input the circle radius (Radius > 0):"); scanf("%f", &fRadius);
/* [b] : Check that the radius in greater than zero */
if( fRadius <= 0 ) { printf("ERROR >> Circle radius must be greater than zero\n"); exit (1);}
/* [c] : Compute Area of Circle */
fPi = 4.0*atan( 1.0 ); fArea = fPi*fRadius*fRadius;
/* [d] : Print Radius and Area */ printf("Radius of Circle = %8.3f \n", fRadius ); printf("Area of Circle = %8.3f \n", fArea );
return (0);}