This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/Lectures/LC10/SimpleFunctions1/simple_functions_1.c

49 lines
1.1 KiB
C
Raw Permalink Normal View History

2022-04-07 15:58:01 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <math.h> // Needed to give access to M_PI
/* FUNCTION: CalculateAreaOfCircle
INPUTS: radius float
RETURNS: area float
Description
Calculate area using area = M_PI * radius * radius
*/
float CalculateAreaOfCircle ( float radius );
2022-04-07 15:58:01 +00:00
/* Show use of function */
int main (void)
{
// Declare variables - no need to initialise as values will be read in / calculated
float rad, Area;
// Prompt for and obtain value
printf ("Please enter the raduis of the circle: ");
scanf ("%f", &rad);
// Use our function to calculate the area
Area = CalculateAreaOfCircle(rad);
// And display the answer on the screen
printf ("The area of a circle of radius %f is %f\n", rad, Area );
// Note: As the function returns a value, if we did not need to store it
// we could calculate & display within the printf statement
//printf ("The area of a circle of radius %f is %f\n", rad, CalculateAreaOfCircle(r) );
// All done
return 0;
}
float CalculateAreaOfCircle ( float radius )
{
float area;
area = M_PI * radius * radius ;
return (area) ;
}