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 a number in feet, converts it to meters, and displays the result. One foot is 0.305 meter.

Body Mass Index (BMI) is a measure of health based on height and weight. You can calculate your BMI by taking your weight in kilograms and dividing it by the square of your height in meters

Write a program that prompts the user to enter the coordinates of two points (x1, y1) and (x2, y2), and displays the slope of the line that connects the two points. The formula of the slope is (y2 - y1)/(x2 - x1).