Sunday, July 26, 2009

C Program problem?

"A square w/ one side"


x centimeter long is inscribed a circle write a C program that computes %26amp; output the qrea of the circle.

C Program problem?
so the square's in the circle?


thus the diameter of the circle is the distance from opposite points of the square...





float getAreaOfCircle ( const float%26amp; sideLength ) {


float areaOfCircle =0;





if ( sideLength %26gt; 0 ){


// edge to opposite edge of a square is (the square root of 2)*edge length


const float root2 =1.41;





const float pi =3.1415926;





const float diameter = root2 * sideLength;





//area of circle is pi D squared / 4


areaOfCircle = pi * diameter * diameter * 0.25;





}





return areaOfCircle;


}





(sort the indenting out yourself...)


No comments:

Post a Comment