The circle’s circumference — the measure of the total length around the shape — is determined based on the fixed ratio of Pi. In degrees, a circle is equal to 360° and Pi (p) is the fixed ratio equal to 3.14.
Area: p * r * r
Perimeter: 2 * p * r
C++ Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> #include<stdlib.h> #include <cmath> using namespace std; int main() { double r,area,perimeter; cout<<"Input Radius : "; cin>>r; area=M_PI*r*r; perimeter=2*M_PI*r; cout<<"Area of Circle : "<<area<<endl; cout<<"Perimeter of Circle : "<<perimeter; } |
Output:
This is a C++ program that calculates the area and perimeter of a circle, given the radius as input from the user.
The program starts by including the necessary libraries, iostream for input and output, stdlib.h for general purpose functions and cmath for mathematical functions.
In the main function, the program declares two double variables r, area, and perimeter.
It then uses cout to prompt the user to input the radius of the circle, and uses cin to accept the input value and store it in the variable r.
The program then calculates the area of the circle using the formula Area = PI * r^2, where PI is a predefined constant in cmath library. The same formula is used to calculate the perimeter of the circle which is 2PIr.
It then uses cout to display the area and perimeter of the circle, with the value of the area and perimeter being calculated from the previous step.
This program uses mathematical functions from the cmath library to calculate the area and perimeter of a circle, based on user input for the radius. It then displays the results to the user.