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 reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.

Write a program that prompts the user to enter the min- utes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days