Answer to Question #337931 in C++ for namio

Question #337931

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


1
Expert's answer
2022-05-06T15:35:56-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS