Skip to main content

Posts

Showing posts with the label pyramid

Volume of pyramid in using Matlab

Problem Write a script to calculate the volume of a pyramid, which is 1/3 * base * height,  where the base is length * width. Prompt the user to enter values for the length,  width, and height, and then calculate the volume of the pyramid. When the user  enters each value, he or she will then also be prompted for ‘i’ for inches or ‘c’ for  centimeters. (Note: 2.54 cm  = 1 inch.) The script should print the volume in cubic  inches with three decimal places. As an example, the output format will be: This program will calculate the volume of a pyramid. Enter the length of the base: 50 Is that i or c? i Enter the width of the base: 6 Is that i or c? c Enter the height: 4 Is that i or c? i The volume of the pyramid is xxx.xxx cubic inches. Solution This problem has been taken from the book A Practical introduction to Matlab by stormy Attaway . This is a must read book for Matlab programmers. This will make your path to success in Matlab easy and y...