In: Computer Science
Write a program to compute answers to some basic geometry formulas. The program prompts the user to input a length (in centimeters) specified as a floating point value. The program then echoes the input and computes areas of squares and circles and the volume of a cube. For the squares, you will assume that the input length value is the length of a side. For the circles, this same value becomes the diameter. Use the meter value input to calculate the results in square (or cubic) meters and then print the answers in square (or cubic) meters. Area of a square (length times width) Area of a circle (pi times radius squared) How much bigger the area of the square is than the circle (see previous calculations) Round the length down to the next whole number of meters, compute the volume of a cube with this value as the length of its side Round the length up to the next whole number of meters, compute the volume of a cube with this value as the length of its side. You are to run the program three times using the following input values: 1000 1999.9 299.4 Please turn in the program and the outputs of running the program three times as directed. Be sure to use good style, appropriate comments and make use of constants in this program. Important Notes For the constant PI, please use 3.14159 Use the floor() and ceil() functions to round down and up respectively. For example, ceil(3.02) is 4. Be sure to #include to get access to these two functions Sample Output Your output format should look similar in style to the one below. Geometry formulas by (Your name) Enter one floating point number for length, 123.4 The number you entered is 123.4 cm or 12.34xx m. Area of square xx.xxxxxxx sq. m. Area of a circle xx.xxxxxxx sq. m. Difference is xx.xxxxxxxx sq. m. Cube volume rounded down is xx.xxxxxxxx cu. m. Cube volume rounded up is xx.xxxxxxxx cu. m. Press any key to continue
#include <stdio.h>
#include <math.h>
#define PI 3.14159
int main(){
float length;// centimeters
printf("\nGeometry formulas by [Name]");
printf("\nEnter one floating point number for length: ");
scanf("%f",&length);
printf("\nThe number you entered is %0.1f cm",length);
length = length/100; // to meters
float square_area = length*length;
float circle_area = PI*(length/2)*(length/2); // radius =
diameter/2
float difference = square_area - circle_area;
//
float cube_volume_down =
floor(length)*floor(length)*floor(length);
float cube_volume_up =
ceil(length)*ceil(length)*ceil(length);
//
printf("\nArea of square %0.7f sq.m",square_area);
printf("\nArea of circle %0.7f sq.m",circle_area);
printf("\nDifference is %0.7f sq.m",difference);
//
printf("\nCube volume rounded down is %0.7f
cu.m",cube_volume_down);
printf("\nCube volume rounded up is %0.7f
cu.m",cube_volume_up);
//
printf("\nPress any key to continue");
return 0;
}
------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~