Translate

Write a program that reads in the radius of a circle and prints the circle’s diameter


Question:
Write a program that reads in the radius of a circle and prints the circle’s diameter, circumference and area. Use the constant value 3.14159 for phi. Do these calculations in output statements. (Note: In this chapter, we have discussed only integer constants and variables. In Chapter 3 we will discuss floating-point numbers, i.e., values that can have decimal points.)

Answer:


#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