10/08/2007

3.2 == 請同學練習找出下列程式錯誤之處並修正

#include /* Standard Input/Output function declarations */
#include

int main( void ) {

float fRadius; /* Radius of circle */
float fArea; /* Area of circle */


/* [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( 2.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);
}

0 Comments:

張貼留言

<< Home