Write a C++ program to input the radius of a circle from user and find diameter,
circumference and area of the given circle using function.
Use the following formula:
Diameter = 2r
Circumference = 2 π r
Area = π r2
Note: π = 3.14
#include <iostream>
using namespace std;
int main() {
const float pi=3.14;
float r, diameter, area, cicumference;
cout<<"Enter integer r: ";
cin >> r;
if(!cin||r<0){
cout<<"Invalid input."<<endl;
cin.clear();
exit(1);
}
diameter = 2*r;
cicumference = 2*pi*r;
area = pi*r*r;
cout<<"diameter: "<<diameter<<endl;
cout<<"cicumference: "<<cicumference<<endl;
cout<<"area: "<<area<<endl;
cout<<endl;
return 0;
}
Comments
Leave a comment