Saturday, October 27, 2012

Calculation Volume of Trangular Pyramid and Volume sphere

Name :Chea Lida
Major: TMD




http://www.youtube.com/watch?v=pOPw2W8jzy0&feature=youtu.be




#include<stdio.h>
#include<stdlib.h>
int main()
{
    int i ;
    float b, h1,h2,v;
    float r ,pi=3.14159;
    do
    {
    printf("Please input number 1 to Calculate Volume of triangular pyramid and number 2 to calculate Volume of sphere:\n");
    scanf_s("%d",&i);//include 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 triangular:");
                scanf_s("%f",&h1);
                printf("Enter height of Pyramid:");
                scanf_s("%f",&h2);
                v=(((b*h1)/2)*h2)/3;//formula for calculate Volume of triangular pyramid
                printf("The volume of triangular pyramid is: %f \n",v);
                break;
            case 2://if value equal 2, statement in case 2 execute
                printf("calculate the volume of sphere \n ");
                printf("Enter radius:");
                scanf_s("%f",&r);
                v=(4/3)*pi*(r*r*r);//formula for calculate Volume of sphere
                printf("The volume of sphere is: %f \n",v);
                break;
            default:
                printf("you do not type a number 1 or 2\n\n");
                break;

        }
    }while((i!=1)&&(i!=2));//if inputing of i differance to 1 and 2 must input again
    system("pause");
    return(0);













No comments:

Post a Comment