Computer Science, asked by anbunilavendhan, 20 hours ago

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 anindyaadhikari13
5

\textsf{\large{\underline{Solution}:}}

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 co‎de. 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