move exercises and lectures into subfolders

This commit is contained in:
2023-10-15 15:34:53 +01:00
parent 775b4bd643
commit 74092a17aa
177 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float LineLength(float x1, float x2, float y1, float y2);
int main()
{
float p1x = 3.4, p2x = 5.7, p1y = 0.0, p2y = 6.8;
float length = 0;
length = LineLength(p1x, p2x, p1y, p2y);
printf("Length = %f", length);
return 0;
}
float LineLength(float x1, float x2, float y1, float y2)
{
float result;
float dx = x2-x1;
float dy = y2-y1;
float tol = 1e-10;
if (fabs(dx) < tol && fabs(dy) < tol )
return -1;
result = sqrt(dx*dx + dy*dy);
return result;
}

View File

@@ -0,0 +1,32 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// As we are using the function BEFORE it is actually written we need to provide the
// prototype so that the compiler can verify we are calling it correctly
void CalculateArea ( double Radius, double *pArea); // note the *
// This is the main code for our application
int main()
{
double radius, area;
radius = 1.0;
CalculateArea (radius, &area);
printf ("The area of circle of radius %f is %f\n", radius, area);
return 0;
}
// And here is our function
// Note: Pi is written out simply to match the notes, M_PI could also be used
void CalculateArea ( double Radius, double *pArea )
{
*pArea = 3.14159265 * Radius * Radius;
return;
}

View File

@@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// As we are using the function BEFORE it is actually written we need to provide the
// prototype so that the compiler can verify we are calling it correctly
void CalculateVolumeAndSA ( double Radius, double Length, double *Volume, double *SurfaceArea); // note the <20>*<2A>
// This is the main code for our application
int main()
{
double radius = 3.4, length = 7.3, volume, SurfaceArea;
CalculateVolumeAndSA(radius, length, &volume, &SurfaceArea);
printf("The volume is %f \n", volume);
printf( "The surface area is %f\n", SurfaceArea);
return 0;
}
// And here is our function
void CalculateVolumeAndSA ( double Radius, double Length, double *Volume, double *SurfaceArea) // note the <20>*<2A>
{
*Volume = M_PI * Radius * Radius * Length;
*SurfaceArea = ( 2 * M_PI * Radius * Radius * Length ) +( 2 * M_PI * Radius * Length );
}