Added exercise 4.28
[Cpp-Deitel-Exercises.git] / Chapter-2 / 2-20.cpp
blobf86bca79b4b5a50ae2be50db4d42685c71282f05
1 /* C++ How to Program, 9/E, by Paul Deitel & Harvey Deitel.
3 Solution of exercise 2.20:
4 (Diameter, Circumference and Area of a Circle) Write a program that reads in
5 the radius of a circle as an integer and prints the circle's diameter,
6 circumference and area. Use the constant value 3.14159 for π. Do all
7 calculations in output statements. [Note: In this chapter, we’ve discussed
8 only integer constants and variables. In Chapter 4 we discuss floating-point
9 numbers, i.e., values that can have decimal points.]
11 Written by Juan Carlos Moreno (jcmhsoftware@gmail.com), 2022/01/02 */
13 #include <iostream>
15 using namespace std;
17 int main()
19 int radius;
21 cout << "Enter radius of the circle: ";
22 cin >> radius;
24 cout << "Diameter of the circle is " << 2*radius << endl; //D = 2r
25 cout << "Circumference of the circle is " << 2*3.14159*radius //C = 2πr
26 << endl;
27 cout << "Area of the circle is " << 3.14159*radius*radius //A = πr^2
28 << endl;
30 return 0;