Monday 9 September 2024

Write a program to Calculate the Area of a Circle using Function.

 #include <iostream.h>

#include<conio.h>

 

// Function to calculate the area of a circle


double calculateAreaOfCircle(int radius)

 {

 // The formula: π * radius^2

    

return PI * radius * radius;

}


int main() 

{

   int radius, area;


    // Input radius

    cout << "Enter the radius of the circle: ";

    cin >> radius;


    // Call the function to calculate the area

    area = calculateAreaOfCircle(radius);


    // Display the result

    cout << area;

getch();

    return 0;

}