Changes to file structure for VSCode and bug fixes
This commit is contained in:
17
LC20/AreaFunc.c
Normal file
17
LC20/AreaFunc.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
float CalculateAreaOfCircle ( float radius )
|
||||
{
|
||||
float area;
|
||||
area = M_PI * radius * radius ;
|
||||
return (area) ;
|
||||
}
|
||||
|
||||
float CalculateSurfaceAreaOfCylinder ( float radius, float length )
|
||||
{
|
||||
float area;
|
||||
area = 2.0 * ( M_PI * radius * radius ) + ( M_PI * 2.0 * radius * length ); // two ends + side
|
||||
return (area) ;
|
||||
}
|
2
LC20/AreaFunc.h
Normal file
2
LC20/AreaFunc.h
Normal file
@@ -0,0 +1,2 @@
|
||||
float CalculateAreaOfCircle ( float radius );
|
||||
float CalculateSurfaceAreaOfCylinder ( float radius, float length );
|
34
LC20/Main.c
Normal file
34
LC20/Main.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include"AreaFunc.h"
|
||||
|
||||
/* Show use of function */
|
||||
int main (void)
|
||||
{
|
||||
// Declare variables - no need to initialise as values will be read in / calculated
|
||||
float rad, len, Area, SurfaceArea;
|
||||
|
||||
// Prompt for and obtain value
|
||||
printf ("Please enter the raduis of the circle: ");
|
||||
scanf ("%f", &rad);
|
||||
|
||||
printf ("Please enter the length of the cylinder: ");
|
||||
scanf ("%f", &len);
|
||||
|
||||
// Calculate the area of the circle
|
||||
Area = CalculateAreaOfCircle(rad);
|
||||
|
||||
// And display the answer on the screen
|
||||
printf ("The area of a circle of radius %f is %f\n", rad, Area );
|
||||
|
||||
// Calculate the surface area of the cylinder
|
||||
SurfaceArea = CalculateSurfaceAreaOfCylinder(rad, len);
|
||||
|
||||
// And display the answer on the screen
|
||||
printf ("The surface area of a cylinder of radius %f and length %f is %f\n", rad, len, SurfaceArea );
|
||||
|
||||
// All done
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user