#include #include static const double pi = 3.14159265358979; void heading(const char *text) { printf("\n%s\n________\n\n", text); } void prompt(unsigned int count, ...) { unsigned int i; va_list va; va_start(va, count); for (i = 0; i < count; i++) { printf("Please enter %s : ", va_arg(char*)); scanf("%f", va_arg(float*)); printf("\n"); } va_end(va); } void tail(void) { puts("**********************************************************"); fflush(stdin); } main() { puts(" >>>>This program calculates many geometrical formulas<<<<"); { float length; float width; float peri; heading("Perimeter of Square and Rectangle"); prompt(2, "the length of side a", &length, "the length of side b", &width); peri = 2 * (length + width); printf("The perimeter of the square/rectangle is %.2f units squared\n", peri); tail(); } { float lengthl; float widthw; float arealw; heading("Area of Square and Rectangle"); prompt(2, "the length of side a", &lengthl, "the length of side b", &widthl); arealw = lengthl * widthw; printf("The area of the square/rectangle is %.3f units squared\n", arealw); tail(); } { float sidea; float sideb; float sidec; float perimeter; heading("Perimeter of Triangle"); prompt(3, "the length of side a", &sidea, "the length of side b", &sideb, "the length of side c", &sidec); perimeter = sidea + sideb + sidec; printf("The perimeter of the triangle is : %.2f units\n", perimeter); tail(); } { float base; float height; float area; heading("Area of Triangle"); prompt(2, "the length of the base", &base, "the length of the height", &height); area = .5 * (base * height); printf("The area of the triangle is %.2f units squared\n", area); tail(); } { float areabase; float perimeterbase; float side3len; float surareat; heading("Triangular Prism"); prompt(3, "the perimeter of base", &perimeterbase, "the area of base", &areabase, "the length of side h", &side3len); surareat = 2 * areabase + perimeterbase * side3len; printf("The surface area of the triangular prism is : %.3f units squared\n",surareat); tail(); } { float s1; float s2; float s3; double surarea; heading("Rectangular Prism"); prompt(3, "the length of s1", &s1, "the length of s2", &s2, "the length of s3", &s3); surarea = 2 * s1 * s2 + 2 * s2 * s3 + 2 * s1 * s3; printf("The surface area of the rectangular prism is : %.4f units squared\n", surarea); tail(); } { float s1c; float surareac; heading("Cube"); prompt(1, "the length of one side", &s1c); surareac = 6 * s1c *s1c; printf("The surface area of the cube is : %.3f units squared\n", surareac); tail(); } { float sphererad; double spherearea; heading("Sphere"); prompt(1, "the radius of the sphere", &sphererad); printf("\n"); spherearea = 4 * pi * sphererad * sphererad; printf("The surface area of the sphere is %.4f units squared\n", spherearea); tail(); } getchar(); }