Program to Calculate Area of Circle using Function in C Language

Spread the love
area-of-circle-using-function-in-c-programming-language

Area of Circle using Function in C Program Description:

Write a Program to calculate the Area of Circle using function in C programming language, The program should accept the radius ( r) as the input and calculate the area using a C function.

Area of Circle Formula:

Here is the formula to calculate the area of the Circle.

        Area = π × r^2

The area of a circle is π (Pi) times the Radius squared. Where the π (Pi) is 22/7 or 3.142. 

Example Input and Output:

Input:

Enter the radius of Circle: 5

Output:

Area of Circle with 5.000000 radius is : 78.500000

Pre-Requisites:

It is recommended to know the basics of the C Functions, Please go through the following article to learn more about Functions in the C language

Area of Circle using Function in C Algorithm:

  • Take the circle radius value from the user and store it variable called radius.
  • we won’t accept the negative value for radius, So display an error message if the radius is a negative value.
  • We also defined a function named getArea, The getArea function accepts a float value ( radius) as the input, it will calculate the area of the circle using π × r^2 formula and returns the result back to the caller.
  • Call the getArea function from the main function. Pass the radius as the argument. The getAread function returns the area of the circle( float), We will store it in the area variable .
  • Print the results on the console using the printf function.

Area of Circle using Function in C Program:

Here are the prototype details of the getArea function.

  • function_name : getArea
  • arguments_list: float
  • return_type: float
  • Description: Calculate the Area of a circle with a given radius and return it.

Save the above program using the .c extension.

Program Output:

Let’s compile and run the program. We are using the GCC compiler on Linux to run the program.

$ gcc area-circle-func.c

Run the program.

Test Case 1: Positive numbers – Float and Integer Numbers as Radius.

area-of-circle-using-function-in-c-program-output

Test Case 2: Negative Numbers:

Related Programs:

  1. C Program to Print Numbers in Reverse Order
  2. C Program to Calculate Sum of First N natural numbers
  3. C Program to Reverse a Number
  4. C Program to Calculate Sum of Digits of a Number
  5. C Program to Calculate Product of Digits of a Number
  6. C Program to Count the number of Digits of a Number
  7. C Program to Multiply without using Multiplication operator (*)
  8. C Program to generate Fibonacci Series up to a given number

Venkat

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

3 Responses

  1. […] Area of Circle using Function in C […]

  2. […] Program to Caclulate Area of Circle using Function […]

  3. […] Program to Caclulate Area of Circle using Function […]

Leave a Reply