All pastes #524148 Raw Edit

john3

public c v1 · immutable
#524148 ·published 2007-05-31 00:27 UTC
rendered paste body
#include <stdio.h>#include <stdarg.h>static const double pi = 3.14159265358979;void heading(const char *text){   printf("\n%s\n________\n\n", text);}void prompt(const char *text, float *var){   printf("Please enter %s : ", text);   scanf("%f", var);   printf("\n");}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("the length of side a", &length);      prompt("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("the length of side a", &lengthl);      prompt("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("the length of side a", &sidea);      prompt("the length of side b", &sideb);      prompt("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("the length of the base", &base);      prompt("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("the perimeter of base", &perimeterbase);      prompt("the area of base", &areabase);      prompt("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("the length of s1", &s1);      prompt("the length of s2", &s2);      prompt("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("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("the radius of the sphere", &sphererad);      spherearea = 4 * pi * sphererad * sphererad;      printf("The surface area of the sphere is %.4f units squared\n", spherearea);      tail();   }   getchar();}