Consider the following C++ program in which the statements are in the incorrect order.
Rearrange the statements so that it prompts the user to input the radius of a circle and outputs the area and circumference of the circle.
#include <iostream>
Â
{
Â
int main()
Â
cout << "Enter the radius: ";
Â
cin >> radius;
Â
cout << endl;
Â
double radius;
double area;
Â
using namespace std;
Â
return 0;
Â
cout << "Area = " << area << endl;
Â
area = PI * radius * radius;
Â
circumference = 2 * PI * radius;
Â
cout << "Circumference = " << circumference << endl;
Â
const double PI = 3.14;
Â
double circumference;
}
#include <iostream>
using namespace std;
int main()
{
  const double PI = 3.14;
  Â
  cout << "Enter the radius: ";
  double radius;
  cin >> radius;
  double area;
  area = PI * radius * radius;
Â
  double circumference;
  circumference = 2 * PI * radius;
  cout << endl;
  cout << "Area = " << area << endl;
  cout << "Circumference = " << circumference << endl;
  return 0;
}
Comments
Leave a comment