Monday, October 29, 2012

How to calculate volume Pyramid and Sphere.

Name  : Chhorn Bros
Major  : TMD

Here I explain about how to calculate volume of triangular Pyramid and volume of Sphere and I think  it is not good but it can make your idea better.

Code
#include<stdio.h>  // Access file stdio.h Library
#include<stdlib.h>
#include<math.h>
int main()
{
int i;
float b,h1,h2,r,pi=3.14159,v;
do
{
printf("Enter number 1 to Calculate Volume of triangular pyramid.\n");
printf("Enter number  2 to calculate Volume of sphere:\n");
printf("Please chose number to Calculate:");
scanf_s("%d",&i); //Enter value i from Keyboard.
switch(i)
{
case 1: // if value equal 1, statement in case 1 execute
printf("Calculate the volume of triangular pyramid \n ");
printf("Enter Base:");
scanf_s("%f",&b);
printf("Enter height of base triangle:");
scanf_s("%f",&h1);
printf("Enter height of Pyramid:");
scanf_s("%f",&h2);
v=(b*h1*h2)/6;//formula for calculate Volume of triangular pyramid.
printf("The volume of triangular pyramid is: %f \n",v);
system("lcs");
break;
case 2: //if value equal 2, statement in case 2 execute
printf("Calculate the volume of sphere \n ");
printf("Enter radius of sphere:");
scanf_s("%f",&r);
v=((4/3)*pi*(pow(r,3)));//formula for calculate Volume of sphere
printf("The volume of sphere is: %f \n",v);
system("lcs");
break;
default:
printf("You have to chose first 1 or 2 to Calculate.\n");
break;
}

        while((i!=1)&&(i!=2)); //if you input  difference  number 1 and 2 you must input again.
system("pause");
return(0);








Link to Video
http://www.youtube.com/watch?v=F66qv_Lzhhw&feature=youtu.be

No comments:

Post a Comment