C++ constant variable program and area of circle program
C++ constant variable program and area of circle program
copy
#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;
}
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.
Comments
Post a Comment
Any doubt about programming or questions