C++ Program to find Volume and Surface Area of a Cone

Write a C++ Program to Find the Volume and Surface Area of a Cone with an example. This C++ program allows users to enter the height and radius of a cone. Next, we calculate the Length of a Slant, Surface Area, Lateral Surface Area, and Volume of a cone using mathematical formulas. They are

  • C++ Length of a Cone = √h² + r²
  • C++ Volume of a Cone = 1/3 πr²h
  • C++ Surface Area of a Cone = πrl + πr²
  • C++ Lateral Surface Area of a Cone= πrl
#include<iostream>
#include <cmath>
using namespace std;

int main()
{
	float cn_Radius, cn_Height, cn_sa, cn_Volume, cn_LSA, cn_len;
	
	cout << "\nPlease Enter the Radius of a Cone = ";
	cin >> cn_Radius;
	
	cout << "\nPlease Enter the Height of a Cone = ";
	cin >> cn_Height;
	
	cn_len    = sqrt(cn_Radius * cn_Radius + cn_Height * cn_Height);
	cn_sa     = M_PI * cn_Radius * (cn_Radius + cn_len);
	cn_Volume = (1.0/3) * M_PI * cn_Radius * cn_Radius * cn_Height;
	cn_LSA    = M_PI * cn_Radius * cn_len; //cn_LSA= Lateral Surface Area of cone
	
	cout << "\nLength of a Side(Slant)of a Cone    =  " << cn_len;
	cout << "\nThe Surface Area of a Cone          =  " << cn_sa;
	cout << "\nThe Volume of a Cone                =  " << cn_Volume;
	cout << "\nThe Lateral Surface Area of a Cone  =  " << cn_LSA;
		
 	return 0;
}
C++ Program to find Volume and Surface Area of a Cone