Написать программу в СИ++ Радиус круга задать в главной функции. По желанию пользователя в отдельной функции вычислить, либо площадь круга, либо длину окружности. Результат вывести в главной функции
cout << "Enter the radius of the circle: "; cin >> radius; cout << "Do you want to calculate the area (a) or the perimeter (p) of the circle? "; cin >> choice; if (choice == 'a') { cout << "The area of the circle is: " << calculateArea(radius) << endl; } else if (choice == 'p') { cout << "The perimeter of the circle is: " << calculatePerimeter(radius) << endl; } else { cout << "Invalid choice. Please enter 'a' for area or 'p' for perimeter." << endl; } return 0;
using namespace std;
double calculateArea(double radius) {
return M_PI * pow(radius, 2);
}
double calculatePerimeter(double radius) {
return 2 M_PI radius;
}
int main() {
cout << "Enter the radius of the circle: ";double radius;
char choice;
cin >> radius;
cout << "Do you want to calculate the area (a) or the perimeter (p) of the circle? ";
cin >> choice;
if (choice == 'a') {
cout << "The area of the circle is: " << calculateArea(radius) << endl;
} else if (choice == 'p') {
cout << "The perimeter of the circle is: " << calculatePerimeter(radius) << endl;
} else {
cout << "Invalid choice. Please enter 'a' for area or 'p' for perimeter." << endl;
}
return 0;
}