Print Friendly and PDF
(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 can have decimal points.]
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 can have decimal points.]

Solution: 

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
 
int main()
{
   double pi = 3.14159;
   int radius;
 
  cout << "Please enter the radius: ";
  cin >> radius;
 
  cout << "The diameter is " << 2 * radius << endl;
  cout << "Circumference is " << 2 * pi * radius << endl;
  cout << "The area of circle is " << pi * radius * radius << endl;
 
   return 0;
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: