12 : C Program to Calculate Volume of Pyramid

Check out the complete list of c-programs : C Program List    



To calculate the volume of Pyramid, you need to ask user to enter breadth and height of Pyramid.

Variables :

1. breadth : (Datatype int) : to represent the breadth 1 of pyramid.

2. height : (Datatype int) : to represent the height of pyramid.

5. volume_of_pyramid : (Datatype float) : to store volume of pyramid calculated.





Functions :

printf() : is used to display something on the console/screen. Format specifier %d in printf function is used to display a int variable on screen and %lf for float. \n is used to add a newline

scanf() : is used to fetch data inputted by the user on the console/screen using keyboard. %d in scanf is indicates that inputted text is of type int and %f for float.







Formula :

Volume of a Pyramid : (1/3) x Breadth x Height


/*
 * 1000+ C programs + tutorials
 *
 *
 * 12_calculate_volume_of_pyramid.c
 *
 *
 *  Created on: Oct 20, 2014
 *  Author: Code2care.org
 */

#include <stdio.h>
//#include <conio.h>

void main() {

    int breadth;
    int height;
    float volume_of_pyramid;

//	clrscr();

	printf(" Program to calculate Volume of a Pyramid :  ");

	printf("\n\n Enter the Breadth of Pyramid : ");
	scanf("%d", &breadth);
    
    printf("\n\n Enter the Height of Pyramid : ");
	scanf("%d", &height);
    
    
    volume_of_pyramid = (1/3)*breadth*height;


	printf("\n\n Volume of Pyramid with Breadth as %d and Height as %d = %f",breadth,height,volume_of_pyramid);

//	getch();



}








The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.