Write a program in C++ to allow users to input the radius of a circle and print the area and perimeter of the circle using the variable declarations and const declaration for the value of pi.
Answers
Answered by
5
The given problem is solved using language C++.
#include <iostream>
using namespace std;
int main() {
const float PI=3.14;
float radius, perimeter, area;
cout<<"Enter radius of the circle: ";
cin>>radius;
perimeter=2*PI*radius;
area=PI*radius*radius;
cout<<"Perimeter: "<<perimeter<<endl;
cout<<"Area: "<<area;
return 0;
}
The value of pi is declared as constant in this code. If we try to change its value, an error will occur.
The perimeter and area of the circle are calculated using known formulas and they are displayed on the screen.
See the attachment for output.
Attachments:
Similar questions