C++ constant variable program and area of circle program

C++ constant variable program and area of circle program
#Beginner

In gcc c++ compiler using namespace std;



#include<iostream>
using namespace std;

int main()
{
/* constant variable always denote in capital letter */
const double PI = 3.14159;
//step 1 : read radius from user
cout<<"enter the radius of circle :";
double radius;
cin>>radius;
cout<<endl;
// step 2 : compute area
double area = radius * radius * PI ;
//step 3 : show area
cout<<"area of the circle is : "<<area;
}
copy


Output

enter the radius of circle :13

area of the circle is : 530.929
[Program finished]


Constant variable always declared in upper alphabet eg. const double PI ;  you can't use π as variable name therefore pi and PI is allowed but you defined constant the use variable name PI to simply understand the PI variable is constant variable. the const variable can't change the value.



Need of Programmer

Need of Programmer

Comments

Popular posts from this blog

Write a program that reads in the radius and length of a cylinder and computes the area and volume using the following formulas: area = radius * radius * π volume = area * length

Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distance between them.The formula for computing the distance is

Area and perimeter of an equilateral triangle c++ program