Tuesday 21 July 2020

14. 2.20 (Diameter, Circumference and Area of a Circle) Write a program that reads in the radius of a circle as an integer and prints the circle’s diameter, circumference and area. Use the constant value 3.14159 for π. Do all calculations in output statements. [Note: In this chapter, we’ve discussed only integer constants and variables. In Chapter 4 we discuss floating-point numbers, i.e., values that have decimal points.]

14. 2.20 (Diameter, Circumference and Area of a Circle) Write a program that reads in the radius of a circle as an integer and prints the circle’s diameter, circumference and area. Use the constant value 3.14159 for π. Do all calculations in output statements. [Note: In this chapter, we’ve discussed only integer constants and variables. In Chapter 4 we discuss floating-point numbers, i.e., values that have decimal points.] 

#include <iostream>

using namespace std;

int main()
{
 int radius; // declaration

 cout << "Enter the circle radius: "; // prompt
 cin >> radius;

 cout << "Diameter is " << radius * 2.0
 << "\nCircumference is " << 2 * 3.14159 * radius
 << "\nArea is " << 3.14159 * radius * radius << endl;

 return 0;
 }

No comments:

Post a Comment